Virtual Combo Box in MFC - mfc

I have 10 CComboBox in a tab page and I want to load 10k data to each combobox?
It is taking more time for the tab page to get loaded.
In MFC how to implement virtual combobox like virtual list control?
I need to set default selection in the combobox on loading tab.
Can you please someone give me some ideas?
Thanks

There is no such virtual Combobox in the WinApi, but you have serveral optimizations.
Only load the complete data to the box, if needed. So only when you get the CBN_DROPDOWN event you populate the box with all items. Otherwise you just insert the one selected item.
This method has a drawback that cursor up down in a closed combo doesn't work.
Also you can populate the box only when it receives the focus. Also in this case you just populate the box with the current selected item.
The best result you get is using a owner draw combobox, without using CBS_HASSTRING. CB_ADDSTRING receives a pointer to your data. In DrawItem you use this pointer for drawing.
You still need to add 10k items to each box, but there is no string management and the box is real fast without this memory allocations.

Related

How to deal with MFC listcontrol window flashing

I wrote a MFC application program.I used some ListControl controls and some radio buttons in the dialog.I would like to realize real-time-update data with ListControl when clicked the single radiobutton triggering the corresponding events.
Firstly,when the dialog initialized,inserting data into the ListControl and showing the dialog.
Secondly,when I clicked the one radiobutton among these.The first step was to delete the all columns and all items in the ListControl.The second step was to insert my neccessary data into the ListControl.By the way,I used the same variable relative to the ListControl ID.
Notice:The data was changed by time!
Finally I found that the ListControl window appeared the fast flash and felt so bad.
So is there some good ways to solve this problem?And can you suggest some good or advanced advice to me?Thanks a lot!

Display and use the same MFC CList control in multiple dialogs

I am coding a test application for a windows CE device. This is the first time I am programming for a handheld device. I use MFC VC++ on Visual Studio 2008. I have found that there are many restrictions in the controls and what I could do with them when running the program on a handy versus when I run a similar program on a desktop computer.
Now, the device I am currently deploying my test program to, does not have a touchscreen and has few extra keys other that the numberpad 0-9 keys. So, I have to do with a simple GUI that uses keydowns to call specific functions like add, edit, delete etc... It also forces me to use separate dialogs for each of these functions so as to avoid unnecessary mouse cursor usage.
This leads me to my current problem: The 'ADD' dialog of my test app adds some user data to a CListCtrl that is on the 'MAIN' dialog. The 'EDIT/DELETE' dialog is to allow the user to select the desired data from its own CListCtrl and press the "ENTER" key, which thereby deletes the selected data from the 'MAIN' dialog's CListCtrl. Thus, both the main dialog and the 'EDIT/DELETE' dialog have CListCtrl with the exact same data. So, instead of having to use 2 separate list controls and using loops to copy the data to and fro among them, is there a way in which i could use the exact same CListCtrl (one and only one instance of the CListCtrl exists), but display it on 2 separate dialogs? This would remove all the copying code, as well as halve the amount of data in memory.
I tried passing a pointer to the MAIN dialog's CListCtrl to the 'EDIT/DELETE' dialog in hopes that I could redraw the control there, but in vain. I could call the RedrawWindow, RedrawItems commands, but they seem to have no effect in the 'EDIT/DELETE' dialog (I think it is because the control itself is not present on the edit/delete dialog). Any other suggestions?
You could temporarily change the parent of the ListCtrl using CWnd::SetParent to the EDIT/DELETE dialog, and set the position with CWnd::SetWindowPos to where you want to have it. When the dialog gets closed, set the parent back to the MAIN dialog.

CListCtrl (MFC) selection click passes through to control UNDERNEATH the list

My CListCtrl (Report View, single column) ignores item selection when there's another control behind the CListCtrl. It's as if the click passes through to the control BEHIND the CListCtrl.
Selection is fine if the list item isn't on top of another dialog-box item.
It's baffling because the CListCtrl's z order is ABOVE these other controls. Can anyone suggest something I could try to make the CListCtrl accept a click even when there's another overlapped control? Thanks!
User Spy++ to check the message flow. And to check if another control is above your control! Maybe there is something wrong with you´r z-order even if you think that the control is above. Also check if you overwrote WM_NCHITTEST

Force update of a virtual CListCtrl

I have a CListCtrl containings about 2500 differents elements consisting of a 48x48 icon and text.
Due to the amount of data I implemented it as a virtual list providing
ON_NOTIFY(LVN_GETDISPINFO, IDC_LST_ICONS, &CWGDIconSearchDlg::OnLvnGetdispinfoLstIcons)
ON_NOTIFY(LVN_ODFINDITEM, IDC_LST_ICONS, &CWGDIconSearchDlg::OnLvnOdfinditemLstIcons)
My problem is when I change list content these callback get never called.
How can I force it?
Windows cannot know that you have changed an item in virtual list.
In order to trigger a redraw of your CListCtrl, you must call yourcontrol.Invalidate() which will trigger a repaint of your control.

MFC ListView Cntrl error

I am displaying a ListView cntrl in a modal Dialog box, with ListView properties as "Owner Draw" and "Owner Draw fixed" and using LVN_GETDISPINFO. The dialog along with the list view is getting displayed when there is no data. But strangely, when I am trying to insert data into the list view (by putting data in the array (vector) attached with the list view), my dialog is crashing.
On debugging, the error seems to be coming from the following MFC Library function :
void CListCtrl::DrawItem(LPDRAWITEMSTRUCT)
{
ASSERT(FALSE);
}
In my other applications I have successfully displayed a list control (with Owner draw and Owner data), without subclassing CListCtrl, and overidding DrawItem(). But in my present dialog, I am unable to understand why the list view is failing when I am inserting data into it?
Appreciate your time and help.
Thanks
when you define Owner Draw property, you must implement your own DrawItem function witch draw one item.
You can look for this article