none
Suggestion needed for Storing Listcontrol items. RRS feed

  • Question

  • Hi,

    I am working on a Dialog Based MFC application in VC++ 2012.

    I have a list control on Dialog.

    the list control looks something like this with 2 column:

    Name Age

    Sam 31

    Bob 23

    Kelly 21

    Ron 32

    .... And so on.

    There are around 200 such elements.

    At the run-time, user will be asked to enter the value"Age", otherwise it will be blank. by default only the "Name" column will be displayed with 200 names.

    Now the question is what can be the best data structure I should use to store this data ("Name" & "Age" ) to meet the following conditions:

    1. There can be same name with same age entry in the list.  

    2. Insertion of the "age" value corresponding to any name should be fast inside data structure(best in performance).

    3. The sequence of items it is displaying in GUI the same sequence I need to keep internally also in that data structure.

    4. There is a UP and DOWN arrow button on UI to shift the elements in List control, so same shifting should happen internally also within my data structure.

    So first I thought STL MAP and multiMAP but then they are sorted automatically, I need unsorted DS.

    Please guide me in implementing such DS.

    Thanks in advance,


    Thanks & Regards, Mayank Agarwal

    Friday, October 7, 2016 4:18 AM

Answers

  • Actually previously I though to have a listControl with 2 columns, as there were just 2 fields(Name and age), but later the field got increased with 6 more items. Then I found tough to handle in a list control, so I changed it to listBox.

    Not my list box is having the list of names. Once you double click on any of the list Item one dialog pops up, which is having the list control. this list control dialog is more or less similar to theMFC control property window to input employee details.


    So now you are using a List Box in one dialog and a List View in a separate dialog?

    So can I make use of SetItemDataPtr of listBox to associate the details? and if I move the items of the ListBox UP or DOWN, will its itemdata will move along with the list item?
    Whatever you put in a List Box item's ItemData is associated with that item.

    • Marked as answer by MayankAg Monday, October 24, 2016 5:51 AM
    Friday, October 21, 2016 5:57 AM

All replies

  • Why do you need a data structure when the list-view control itself contains the data?  Is this a homework problem?
    Friday, October 7, 2016 10:25 AM
  • Hi MayankAg,

    thanks for posting here.

    >>Now the question is what can be the best data structure I should use to store this data ("Name" & "Age" ) to meet the following conditions:

    As RLWA32 said, the CListCtrl will store your data by itself.

    You could use CListCtrl::InsertItem, CListCtrl::InsertColumn, CListCtrl::InsertGroup to insert data into List Control and use CListCtrl::FindItem or CListCtrl::GetItem to get the items you want.

    Hope this could be help of you.

    Best Regards,

    Sera Yu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

    • Proposed as answer by Baron Bi Thursday, October 13, 2016 2:09 AM
    Monday, October 10, 2016 9:29 AM
  • Thanks RLWA32 and Sera Yu, and sorry for lat repying.

    But in my case age was just an example to explain my problem, but in actual there is a structure associated with each name. This structure will be filled at the runtime when user double  clicks on any name in the list.

    The user will be filling out the details in corresponding to the name, for example, Address, contact details, age, qualification , etc.

    Now suppose there the 3 persons with the same name in the list. How should I store them so that if the user changes the order of names in the GUI(there are UP and DOWN buttons to move names up or down), the order of its details also should change accordingly. Will this happen automatically? or I need to take care of this programmaticallly?

    Please suggest.


    Thanks & Regards, Mayank Agarwal

    Monday, October 17, 2016 11:52 AM
  • You can tell the list view control to use callbacks to obtain the information to display.  That way the list view will send LVN_GETDISPINFO notifications to the parent window to request data which you would provide from your structure.

    See LVITEM structure and the description of LPSTR_TEXTCALLBACK, and also Callback Items and the Callback Mask

    By using callbacks you would not have to sync the list view data and the data structure manually.

    How are you changing the order of items in the list view control?

    You might consider using a vector for data storage the list view item number would correspond to the position of the data in the vector.

    Another possibility would be to use a map with the list view item number as the key.







    • Edited by RLWA32 Monday, October 17, 2016 3:22 PM clarified suggestions
    Monday, October 17, 2016 12:19 PM
  • Ok, if I set something(a structure) with a list item of the listbox using SetItemDataPtr(). Will that structure will stick to that particular Item even if I move that item up or down in the list?

    Thanks & Regards, Mayank Agarwal

    Friday, October 21, 2016 4:34 AM
  • Ok, if I set something(a structure) with a list item of the listbox using SetItemDataPtr(). Will that structure will stick to that particular Item even if I move that item up or down in the list?

    Please let us know exactly which control you are talking about.  Is it a List View or a List Box

    Friday, October 21, 2016 5:03 AM
  • Actually previously I though to have a listControl with 2 columns, as there were just 2 fields(Name and age), but later the field got increased with 6 more items. Then I found tough to handle in a list control, so I changed it to listBox.

    Not my list box is having the list of names. Once you double click on any of the list Item one dialog pops up, which is having the list control. this list control dialog is more or less similar to theMFC control property window to input employee details.

    The problem I am facing to associate the name(of the list Box of first dialog) with its details(the list control details of the second dialog).

    So can I make use of SetItemDataPtr of listBox to associate the details? and if I move the items of the ListBox UP or DOWN, will its itemdata will move along with the list item?

    And as per your earlier comment now I am not creating MAP or any other data structure

    for storing the items and its details.


    Thanks & Regards, Mayank Agarwal


    • Edited by MayankAg Friday, October 21, 2016 5:24 AM
    Friday, October 21, 2016 5:22 AM
  • Actually previously I though to have a listControl with 2 columns, as there were just 2 fields(Name and age), but later the field got increased with 6 more items. Then I found tough to handle in a list control, so I changed it to listBox.

    Not my list box is having the list of names. Once you double click on any of the list Item one dialog pops up, which is having the list control. this list control dialog is more or less similar to theMFC control property window to input employee details.


    So now you are using a List Box in one dialog and a List View in a separate dialog?

    So can I make use of SetItemDataPtr of listBox to associate the details? and if I move the items of the ListBox UP or DOWN, will its itemdata will move along with the list item?
    Whatever you put in a List Box item's ItemData is associated with that item.

    • Marked as answer by MayankAg Monday, October 24, 2016 5:51 AM
    Friday, October 21, 2016 5:57 AM