Multi Column ListBox
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Multi Column ListBox

  1. #1
    Join Date
    Jul 2003
    Posts
    11

    Multi Column ListBox

    How can make a multicolumn list box (i know how to create it- but don't know how add columns and titles to them, and how to maintain).

    (I'm not using MFC)

  2. #2
    Join Date
    Oct 2002
    Location
    Italy
    Posts
    324
    Why don't you create a list control instead of a multicolumn listbox ?
    It would be easier to create and maintain it, because it features multiple columns already.
    Multicolumn/owner-draw listboxes were useful only when we hadn't common controls (to say, Visual SourceSafe implements even a tree control with a list box).
    Regards,
    Marco Era
    www.marcoera.com

    Latest post on my blog: Back to the Amiga's times

  3. #3
    Join Date
    Jul 2003
    Posts
    11
    Hmm, thanks, I've never thought of it. But i still don't know how to add a title though :/

  4. #4
    Join Date
    Jul 2003
    Posts
    11
    Is there any online tutorials/docs/code samples that demostrate creation and usage of multicolumn listboxes?
    (I do not want to use MFC)

    I'll be glad to see one...

  5. #5
    Join Date
    Jun 2003
    Location
    China,P.R.
    Posts
    37
    Use CListCtrl:

    CListCtrl list;
    list.InsertColumn(0,"Fist Column");
    list.InsertColumn(1,"Second Column");//title between " "
    ...

    I think it accomplishes your requirements.

  6. #6
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by Cortez
    Is there any online tutorials/docs/code samples that demostrate creation and usage of multicolumn listboxes?
    (I do not want to use MFC)

    I'll be glad to see one...
    It would be very, very, very easy to simply add the style to a listbox in a test program and then add half a dozen or a dozen items. You will quickly see that it is a waste of time to do what you are asking to do.

    Multicolumn listboxes don't work the way you think they do and therefore column headers are useless for them. Believe me; the multicolumn style for listboxes is not worth dwelling on.

    CListCtrl For Beginners
    Last edited by Sam Hobbs; August 2nd, 2003 at 10:30 PM.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  7. #7
    Join Date
    Jul 2003
    Posts
    11
    I purely remember saying that I do not want to use MFC.

  8. #8
    Join Date
    Oct 2002
    Location
    Italy
    Posts
    324
    Have a look at the following website:
    ListView overview

    Post here again if you need help.
    Regards,
    Marco Era
    www.marcoera.com

    Latest post on my blog: Back to the Amiga's times

  9. #9
    Join Date
    Jul 2003
    Posts
    11
    OK Here I've created a multi column textbox. Now how do I add items to a specified column?

    Code:
    DWORD dwStyle =	WS_TABSTOP |
    		WS_CHILD |
    		WS_BORDER |
    		WS_VISIBLE |
    		LVS_AUTOARRANGE |
    		LVS_REPORT ;
    		//LVS_OWNERDATA;
    
    // Create the main listbox
    hwndListView = CreateWindowEx(	WS_EX_CLIENTEDGE,		// ex style
    				WC_LISTVIEW,	// class name - defined in commctrl.h
    				"",				// dummy text
    				dwStyle,		// style
    				0,				// x position
    				0,				// y position
    				0,				// width
    				0,				// height
    				hwnd,					// parent
    				(HMENU)ID_LISTVIEW,		// ID
    				hInstance,				// instance
    				NULL);					// no extra data
    
    if(hwndListView == NULL)
    {
    	// some error handling
    }
    
    LV_COLUMN   lvColumn;
    int         i;
    TCHAR       szString[3][30] = {"Hello", "One", "Two"};
    
    //initialize the columns
    lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
    lvColumn.fmt = LVCFMT_LEFT;
    lvColumn.cx = 108;
    for(i = 0; i < 3; i++)
       {
    	  lvColumn.pszText = szString[i];
    	  ListView_InsertColumn(hwndListView, i, &lvColumn);
       }
    
    
    //empty the list
    ListView_DeleteAllItems(hwndListView);
    
    // a function that corrects the listview's width/height
    ResizeListView(hwndListView, hwnd);

  10. #10
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    That is not a "multi column textbox". There is not a "multi column textbox" in the Windows SDK. The documentation has the name of it and has examples of adding items.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  11. #11
    Join Date
    Jul 2003
    Posts
    11
    I know that there'S no multi-column textbox, I mistyped. I meant multi column listview.

    I have MSDN cds, but can't find the example of how to add items in desired columns. This is why I posted a message to this forum, expecting a help.

  12. #12
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Look at Windows Controls. That is an online copy of something you probably have in your local hard drive. In the "List-View" documentation there is a sample program for it. If you have the Platform SDK installed then the sample programs probably have other samples also. With the samples installed in a local hard drive (the default when the SDK is installed) the source files can be searched and many useful things can be found.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  13. #13
    Join Date
    Jul 2003
    Posts
    11
    I already looked the example that is reached from the link you gave, and it ues VIRTUAL multicolumn list view, NOT multi column listview.

    If you read the code I wrote, you could esliy see this too. It's better not to hear advices on usage of MSDN, because it's nothing but a timeloss.

    You could write a small piece of code that adds an item to the listview I created above, and this thread would end. I'll be happy if someone says something that I don't know about the thing I asked .

  14. #14
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    I sure don't understand why it is so difficult to use the following as an example.
    Code:
    typedef struct tagPETINFO
    {
    char szKind[10];
    char szBreed[50];
    char szPrice[20];
    }PETINFO;
    
    // A PETINFO variable is declared and initialized as
    // follows:
    
    PETINFO rgPetInfo[ ] = 
    {
    {"Dog", "Poodle", "$300.00"},
    {"Cat", "Siamese", "$100.00"},
    {"Fish", "Angel Fish", "$10.00"},
    };
    
    // Some code to create the list-view control.
    // Initialize LVITEM members that are common to all
    // items.
    lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
    lvI.state = 0;
    lvI.stateMask = 0;
    
    // Initialize LVITEM members that are different for each item.
    for (index = 0; index < 3; index++)
    {
    	lvI.iItem = index;
    	lvI.iImage = index;
    	lvI.iSubItem = 0;
    	lvI.lParam = (LPARAM) &rgPetInfo[index];
    	lvI.pszText = LPSTR_TEXTCALLBACK; // sends an LVN_GETDISP message.
    	if(ListView_InsertItem(hWndListView, &lvI) == -1)
    		return NULL;
    }
    Last edited by Sam Hobbs; August 13th, 2003 at 04:08 PM.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  15. #15
    Join Date
    Jun 2004
    Posts
    2
    The following code will fill in a list box with 8 subitems. No MFC used. Hope this helps. If you need more, e-mail me at Aptom@softhome.net








    LVITEM listItem;
    listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE | LVIF_DI_SETITEM;
    listItem.state = 0;
    listItem.stateMask = 0;


    for(int i = 0; i < numClients; i++)
    {
    listItem.iItem = i;
    listItem.iImage = i;
    listItem.iSubItem = 0;
    listItem.lParam = (LPARAM) NULL;
    listItem.pszText = clientList[i].insuranceCompany; // sends an LVN_GETDISPINFO message
    ListView_InsertItem(listViewHandle, &listItem);

    LVITEM subItem;
    subItem.iItem = i;
    subItem.iSubItem = 1;
    subItem.mask = LVIF_TEXT;
    subItem.pszText = clientList[i].name;
    ListView_SetItem(listViewHandle, &subItem);

    subItem.iItem = i;
    subItem.iSubItem = 2;
    subItem.mask = LVIF_TEXT;
    sprintf(buffer, "%.2f", clientList[i].annualPremium);
    subItem.pszText = buffer;
    ListView_SetItem(listViewHandle, &subItem);

    subItem.iItem = i;
    subItem.iSubItem = 3;
    subItem.mask = LVIF_TEXT;
    sprintf(buffer, "%.2f", clientList[i].modalPremium);
    subItem.pszText = buffer;
    ListView_SetItem(listViewHandle, &subItem);

    subItem.iItem = i;
    subItem.iSubItem = 4;
    subItem.mask = LVIF_TEXT;
    subItem.pszText = clientList[i].modalPaymentType;
    ListView_SetItem(listViewHandle, &subItem);

    subItem.iItem = i;
    subItem.iSubItem = 5;
    subItem.mask = LVIF_TEXT;
    subItem.pszText = clientList[i].paidThroughMonth;
    ListView_SetItem(listViewHandle, &subItem);

    subItem.iItem = i;
    subItem.iSubItem = 6;
    subItem.mask = LVIF_TEXT;
    subItem.pszText = clientList[i].effectiveDate;
    ListView_SetItem(listViewHandle, &subItem);

    subItem.iItem = i;
    subItem.iSubItem = 7;
    subItem.mask = LVIF_TEXT;
    sprintf(buffer, "%.2f", clientList[i].commission);
    subItem.pszText = buffer;
    ListView_SetItem(listViewHandle, &subItem);

    subItem.iItem = i;
    subItem.iSubItem = 8;
    subItem.mask = LVIF_TEXT;
    sprintf(buffer, "%.2f", clientList[i].ytdCommission);
    subItem.pszText = buffer;
    ListView_SetItem(listViewHandle, &subItem);


    }

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center