Help Needed - How to draw Gridlines in ListBox (Non MFC) Win32
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Help Needed - How to draw Gridlines in ListBox (Non MFC) Win32

  1. #1
    Join Date
    Apr 2009
    Location
    Cochin
    Posts
    83

    Exclamation Help Needed - How to draw Gridlines in ListBox (Non MFC) Win32

    Hi all.. i'm having a problem with the Listbox control in a Window. I need to display Gridlines(Horizontical lines) in the listbox control.

    I Searched the MSDN Documentation and found that, the LVS_EX_GRIDLINES style setting can do it for me.. and also, it must be used in conjunction with LVS_REPORT style.

    I tried, but was in vein.. nothing happened.. i used the ListView_SetExtendedStyleView() API and also tried out using the SendMessage() API... And that too failed.

    I searched google for sample codes, but didnt find any useful.. there are soo many codes and articles on MFC, but i dont know MFC.. i need only Win32 code.

    I will post my code snippet here..

    Code:
    icce.dwSize = sizeof(icce);
        icce.dwICC = ICC_LISTVIEW_CLASSES;
        InitCommonControlsEx(&icce);
    
    	hList = CreateWindowEx(WS_EX_CLIENTEDGE,"listbox","MyListBox...",WS_CHILD|WS_VISIBLE|LVS_REPORT ,5,40,480,290,appWindow, (HMENU)1003,hInst,(LPVOID)lpParam);
    	
    	ListView_SetExtendedListViewStyleEx(hList, LVS_EX_GRIDLINES, LVS_EX_GRIDLINES);
    Now, whats wrong with the code, where am i err-ing?

    I use this code inside a function named RenderList() and calls it from the WM_CREATE message handler of the Main window(Parent) hWnd.

    I will apreciate all your valuable inputs..

    Thanks in advance, and i'll vote you for sure if you helps me

  2. #2
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,060

    Re: Help Needed - How to draw Gridlines in ListBox (Non MFC) Win32

    [ Moved thread ]

    LVS_REPORT as LVS_EX_GRIDLINES styles are for listview control (having class name "SysListView32") and not for listbox (having class name "ListBox").
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    My likes on StumbleUpon
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  3. #3
    Join Date
    Apr 2009
    Location
    Cochin
    Posts
    83

    Thumbs up Re: Help Needed - How to draw Gridlines in ListBox (Non MFC) Win32

    Thanks for your most valuable reply, ovidiucucu.

    Actually that will be the problem.. i will try it out, and come back.

    I'll reply if it does works or not..

    [Edit]

    Yes! It worked fine....

    Thanks once again...

  4. #4
    Join Date
    Apr 2009
    Location
    Cochin
    Posts
    83

    Unhappy Re: Help Needed - How to draw Gridlines in ListBox (Non MFC) Win32

    One more help required...

    I have added some columns into the SysListView32 control

    Code :

    Code:
    LVCOLUMN hCtlListView1Column;
    			ZeroMemory(&hCtlListView1Column, sizeof(LVCOLUMN));
    			hCtlListView1Column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
    			hCtlListView1Column.fmt = LVCFMT_LEFT;
    			hCtlListView1Column.cx = 100;
    			hCtlListView1Column.pszText = "Column 1";
    			ListView_InsertColumn(hList, 0, &hCtlListView1Column);
    			hCtlListView1Column.pszText = "Column 2";
    			ListView_InsertColumn(hList, 1, &hCtlListView1Column);
    Now, please tell me how can i set text in the columns? I tried with SendMessage() API

    and passed LB_ADDSTRING... but it didnt get work..

    Thanks in advance...

  5. #5
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,060

    Re: Help Needed - How to draw Gridlines in ListBox (Non MFC) Win32

    Again, LB_ADDSTRING is a message for lisbox and not for listview (this two are quite different controls).
    To a listview you have to send LVM_xxx messages.

    Here is a brief examples which fills a listview with two lines and two columns.
    Code:
        // add two columns
        LVCOLUMN lvc = {0};
    
        lvc.mask = LVCF_TEXT|LVCF_FMT|LVCF_WIDTH|LVCF_SUBITEM;
        lvc.pszText = _T("Column 0"); // text
        lvc.fmt = LVCFMT_LEFT;        // left align text
        lvc.cx = 100;                 // column width
        lvc.iSubItem = 0;             // subitem
        ListView_InsertColumn(hList, 0, &lvc);
    
        lvc.pszText = _T("Column 1"); // text
        lvc.iSubItem = 1;             // subitem
        ListView_InsertColumn(hList, 1, &lvc);
    
        LVITEM lvi = {0};
    
        // add two "empty" items ("rows" for a report style listview)
        lvi.iItem = 0; // item index
        ListView_InsertItem(hList, &lvi);
        lvi.iItem = 1;
        ListView_InsertItem(hList, &lvi);
    
        // set items/subitems text
        ListView_SetItemText(hList, 0, 0, _T("line 0, col 0"));
        ListView_SetItemText(hList, 0, 1, _T("line 0, col 1"));
        ListView_SetItemText(hList, 1, 0, _T("line 1, col 0"));
        ListView_SetItemText(hList, 1, 1, _T("line 1, col 1"));
    Last edited by ovidiucucu; April 23rd, 2009 at 12:19 PM.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    My likes on StumbleUpon
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  6. #6
    Join Date
    Dec 2008
    Posts
    114

    Re: Help Needed - How to draw Gridlines in ListBox (Non MFC) Win32

    Read MSDN and use MS Grid controls instead

  7. #7
    Join Date
    Apr 2009
    Location
    Cochin
    Posts
    83

    Thumbs up Re: Help Needed - How to draw Gridlines in ListBox (Non MFC) Win32

    @ ovidiucucu

    Thanks again bro.. your help is very very appreciative. thanks for sparing your valuable time to prepare a small snippet.

    Actually i wansn't awared about the SysListView32 control. Now i learnt many things about that control.. and surely i read MSDN and got more API's related to this control.

    @ Carl666

    can you please tell more detail about MS Grid? Sorry, i didnt find a match in the MSDN Documentation. can you atleast tell me the corect classname? is it advanced than the listview control?

    Thanks.

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