Results 1 to 6 of 6

Thread: Selecting an item in ListView

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    12

    Angry Selecting an item in ListView

    I have a text box for the user to enter an id number. The user then clicks on a button and if a matching number is found in the id field of the listView, that item becomes selected. Any ideas how I do this??

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    what do you mean by "id field of the listView"? is it the text of the list item the id?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    12
    Sorry, didn't explain very well. The database I'm using has a field called ID which is a number. How do I select the record in the ListView by clicking on a button.

    Hope that makes a bit more sense??

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    well you could use something like this to find the index of the item... only if the ID is the text of the listview item, and only if its the first colum... you can probably change this a bit to make it work for your code. I dont think .NET itself provides a way to search:
    VB Code:
    1. Public Shared Function ListViewFind(ByVal txt As String, ByVal lvw As ListView) As Integer
    2.  
    3.             Dim li As ListViewItem
    4.             For Each li In lvw.Items
    5.                 If li.Text = txt Then
    6.                     Return li.Index
    7.                 End If
    8.             Next
    9.  
    10.             Return -1
    11.         End Function
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    12
    Thanks for the code. I can now get the index. As you've probably guessed I'm a newbie!

    So is there any way I can use this index to automatically select the item in the listview??

    Thanks in advance.

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    12
    Think I've cracked it at last:

    Me.ListView1.Items.Item(intIndex).Selected = True

    Thanks for your help MrPolite.

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