Get Index of a RadListBoxItem

3 posts, 0 answers
  1. Denny
    Denny avatar
    7 posts
    Member since:
    Feb 2005

    Posted 05 Nov 2009 Link to this post

    Hello,

    how can I get the Index of a RadListBoxItem in a RadListBox?

    My current code:
    Dim myItem As New RadListBoxItem  
    AddHandler myItem.Click, AddressOf Me.ListBoxClick  
    Me.RadListBox1.Items.Add(myItem)  
     
     
    Private Sub ListBoxClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)       
     
            Dim myItem As RadListBoxItem = sender   
            Dim myIndex As Integer = ???    <---- How can I get the index?   
     
            Me.RadListBox1.SetSelected(myIndex, True)  
    End Sub  
     
     
     
     
     
     

     

     

     

     

     

     

     

  2. Denny
    Denny avatar
    7 posts
    Member since:
    Feb 2005

    Posted 05 Nov 2009 Link to this post

    Got it:

     

     Dim myIndex As Integer = Me.RadListBox1.Items.IndexOf(myItem) 

     

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Robert
    Robert avatar
    82 posts
    Member since:
    Jun 2009

    Posted 09 Nov 2009 Link to this post

    Hi Denny,

    If you are interested in getting the index of a RadListBoxItem when it is clicked you should be able to use the SelectedIndexChanged event of the RadListBox as well.

        Private Sub RadListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadListBox1.SelectedIndexChanged 
            Dim myIndex = RadListBox1.SelectedIndex 
     
        End Sub 

    - Robert


Back to Top