CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Apr 2013
    Posts
    77

    Selecting Subitem in a list view control?

    How would I go about selecting a subitem in a listview control with just pure Win32 API? I know it's possible with MFC... but I can't use MFC for this project. Right now, when you click on a subitem , it selects only the first column of the row
    i used the following by reffering internet.But its not working.
    HTML Code:
    iSlected=SendMessage(hList,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED);
    ListView_SetItemState(hList,iSlected,LVIS_FOCUSED|LVIS_SELECTED,0x000F);

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Selecting Subitem in a list view control?

    You have to use owner or custom draw list control and make the drawing of all the items/subitem yourself. And it does not matter whether MFC is used or not.
    Victor Nijegorodov

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Selecting Subitem in a list view control?

    You can set the extended style LVS_EX_FULLROWSELECT to select the full row. If you want to highlight (i.e. select) individual columns you need to use owner or custom draw as Victor suggested.

    Btw, many folks tend to put the data in each item and column of the list control and then read it out again in order to use it. In my opinion this is a mistake. Instead, when you add items to the list control, use the SetItemDataPtr feature to store the pointer to the item's data. Then when you need to access the data, you have complete access to the data for the item (rather than trying to read the data out of column 2 of the selected item, for example).

    If you are worried about storing the data twice (i.e. once for the collection where you get the pointers for each item, and again for the strings in the control), then consider using a virtual list control. In fact, using a virtual list control provides faster scrolling and can handle large lists. Once you discover the virtual list control approach, you may never go back to doing it the old, duplicated data way.

  4. #4
    Join Date
    Apr 2013
    Posts
    77

    Re: Selecting Subitem in a list view control?

    I will briefly expalin my application,It is win32 based application.I have to manage database of employee deatils.Maximum entry limited to 1000.and its should be expandable(we can add data @ run time.So scrolling limit should be varying.)Is it needed to use Virtaul list for this application?And please Give me some referance sites to do this application.iam begginner in Coding

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Selecting Subitem in a list view control?

    Quote Originally Posted by manjut19 View Post
    I will briefly expalin my application,It is win32 based application.I have to manage database of employee deatils.Maximum entry limited to 1000.and its should be expandable(we can add data @ run time.So scrolling limit should be varying.)Is it needed to use Virtaul list for this application?And please Give me some referance sites to do this application.iam begginner in Coding
    You shouldn't need a virtual list control for 1000 entries. If Arjay's answer wasn't what you're looking for then it's not really clear what you're trying to do with subitem selection. I can't recommend a specific one, but there are lots of books out there about how to program with MFC, .Net or the Win32 API.

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Selecting Subitem in a list view control?

    Quote Originally Posted by manjut19 View Post
    I will briefly expalin my application,It is win32 based application.
    Well, no matter what your app does, the answer remains what Arjay and Victor already said:
    If you want to highlight (i.e. select) individual columns you need to use owner or custom draw as Victor suggested.
    I have to manage database of employee deatils.Maximum entry limited to 1000.and its should be expandable(we can add data @ run time.So scrolling limit should be varying.)Is it needed to use Virtaul list for this application?
    And how does sub item selection relate to if your list virtual or not?

    And please Give me some referance sites to do this application.iam begginner in Coding
    So, if you're a beginner, maybe you need to borrow some pret-a-porter control made by more skilled people. You could try with Codeproject.
    Last edited by Igor Vartanov; August 9th, 2013 at 07:10 AM.
    Best regards,
    Igor

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured