Programatic Listview item select problems..


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Programatic Listview item select problems..

  1. #1
    Matt Williamson Guest

    Programatic Listview item select problems..

    I'm having trouble with programmatically selecting items in a listview
    and being able to reset that and do it again.. here is a better
    explanation. I have a combo box and a listview. The combo box is an
    input field for a search of the listview. when I do the first search, it
    works perfectly.. But, subsequent searches will not work until I
    physically click an item with the mouse. i.e I'm using

    Call SendMessage(lstview.hwnd, LVM_SETITEMSTATE, -1, LV) to clear it of
    all selections then
    Call SendMessage(lstview.hwnd, LVM_SETITEMSTATE, 0, LV) to select the
    first item in the listview.

    Is there something else I need to feed it to tell it that I did that? I
    mean is it just a visual and not returning that something is actually
    selected? My code for the whole process is long and convoluted, but I
    can post key parts if it will help at all.. is there another way to do
    this? I tried the listview.listitem.selected but I'm getting that it's
    read-only at runtime.. that's why I opted to use the API route..

    TIA

    Matt


  2. #2
    Damit Senanayake Guest

    Re: Programatic Listview item select problems..

    "Matt Williamson" <"N0 $paM-Mattwil"@pce.net> wrote in message
    news:38FA6140.D00F1968@pce.net...

    : Call SendMessage(lstview.hwnd, LVM_SETITEMSTATE, -1, LV) to clear it of
    : all selections then
    : Call SendMessage(lstview.hwnd, LVM_SETITEMSTATE, 0, LV) to select the
    : first item in the listview.

    How are you defining/filling out LV?

    Also, LVIS_SELECTED is &H2, but I suppose you knew that... and Randy posted
    a VB method in another NG.

    Here's a quote from the docs you may want to look at:

    LV_ITEM:
    >>

    state
    Indicates the item's state, state image, and overlay image. The stateMask
    member indicates the valid bits of this member.
    Bits 0 through 7 of this member contain the item state flags. This can be
    one or more of the item state values.

    Bits 8 through 11 of this member specify the one-based overlay image index.
    Both the full-sized icon image list and the small icon image list can have
    overlay images. The overlay image is superimposed over the item's icon
    image. If these bits are zero, the item has no overlay image. To isolate
    these bits, use the LVIS_OVERLAYMASK mask. To set the overlay image index in
    this member, you should use the INDEXTOOVERLAYMASK macro. The image list's
    overlay images are set with the ImageList_SetOverlayImage function.

    Bits 12 through 15 of this member specify the state image index. The state
    image is displayed next to an item's icon to indicate an application-defined
    state. If these bits are zero, the item has no state image. To isolate these
    bits, use the LVIS_STATEIMAGEMASK mask. To set the state image index, use
    the INDEXTOSTATEIMAGEMASK macro. The state image index specifies the index
    of the image in the state image list that should be drawn. The state image
    list is specified with the LVM_SETIMAGELIST message.

    stateMask
    Value specifying which bits of the state member will be retrieved or
    modified. For example, setting this member to LVIS_SELECTED will cause only
    the item's selection state to be retrieved.
    This member allows you to modify one or more item states without having to
    retrieve all of the item states first. For example, setting this member to
    LVIS_SELECTED and state to zero will cause the item's selection state to be
    cleared, but none of the other states will be affected.

    To retrieve or modify all of the states, set this member to (UINT)-1.

    You can use the macro ListView_SetItemState both to set and to clear bits.


    <<
    --
    Damit Senanayake | damit@mvps.org | http://members.xoom.com/damit
    Please reply to newsgroups, not by e-mail. | ICQ: 6930718




  3. #3
    Damit Senanayake Guest

    Re: Programatic Listview item select problems..

    "Matt Williamson" <"N0 $paM-Mattwil"@pce.net> wrote in message
    news:38FA6140.D00F1968@pce.net...

    : Call SendMessage(lstview.hwnd, LVM_SETITEMSTATE, -1, LV) to clear it of
    : all selections then
    : Call SendMessage(lstview.hwnd, LVM_SETITEMSTATE, 0, LV) to select the
    : first item in the listview.

    How are you defining/filling out LV?

    Also, LVIS_SELECTED is &H2, but I suppose you knew that... and Randy posted
    a VB method in another NG.

    Here's a quote from the docs you may want to look at:

    LV_ITEM:
    >>

    state
    Indicates the item's state, state image, and overlay image. The stateMask
    member indicates the valid bits of this member.
    Bits 0 through 7 of this member contain the item state flags. This can be
    one or more of the item state values.

    Bits 8 through 11 of this member specify the one-based overlay image index.
    Both the full-sized icon image list and the small icon image list can have
    overlay images. The overlay image is superimposed over the item's icon
    image. If these bits are zero, the item has no overlay image. To isolate
    these bits, use the LVIS_OVERLAYMASK mask. To set the overlay image index in
    this member, you should use the INDEXTOOVERLAYMASK macro. The image list's
    overlay images are set with the ImageList_SetOverlayImage function.

    Bits 12 through 15 of this member specify the state image index. The state
    image is displayed next to an item's icon to indicate an application-defined
    state. If these bits are zero, the item has no state image. To isolate these
    bits, use the LVIS_STATEIMAGEMASK mask. To set the state image index, use
    the INDEXTOSTATEIMAGEMASK macro. The state image index specifies the index
    of the image in the state image list that should be drawn. The state image
    list is specified with the LVM_SETIMAGELIST message.

    stateMask
    Value specifying which bits of the state member will be retrieved or
    modified. For example, setting this member to LVIS_SELECTED will cause only
    the item's selection state to be retrieved.
    This member allows you to modify one or more item states without having to
    retrieve all of the item states first. For example, setting this member to
    LVIS_SELECTED and state to zero will cause the item's selection state to be
    cleared, but none of the other states will be affected.

    To retrieve or modify all of the states, set this member to (UINT)-1.

    You can use the macro ListView_SetItemState both to set and to clear bits.


    <<
    --
    Damit Senanayake | damit@mvps.org | http://members.xoom.com/damit
    Please reply to newsgroups, not by e-mail. | ICQ: 6930718




  4. #4
    Matt Guest

    Re: Programatic Listview item select problems..

    I got the info strait off of vbNet. this example
    http://www.mvps.org/vbnet/code/comctl/lvselectall.htm
    everything seems to work well, but for some reason, it isn't returning
    anything to the ListView to tell it that the item has been selected
    again. That only happens after I click the first item (although it is
    already selected from the code) so, it seems that it is only a visual
    indication and isn't returning that as the listindex.. which.. now that
    I think about it, could be the answer.. heh.. I'll try setting the
    listindex and seeing if that helps.

    Matt


  5. #5
    Matt Guest

    Re: Programatic Listview item select problems..

    I got the info strait off of vbNet. this example
    http://www.mvps.org/vbnet/code/comctl/lvselectall.htm
    everything seems to work well, but for some reason, it isn't returning
    anything to the ListView to tell it that the item has been selected
    again. That only happens after I click the first item (although it is
    already selected from the code) so, it seems that it is only a visual
    indication and isn't returning that as the listindex.. which.. now that
    I think about it, could be the answer.. heh.. I'll try setting the
    listindex and seeing if that helps.

    Matt


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center