Hey there![]()
I'm using this code to select an item in a ListBox when a user right clicks on it
It works great....but....my list is bigger than the container so a scrollbar appears, I can only rightclick select things that appear in the ListBox when the scrollbar is all the way up, if I scroll down and try to rightclick select something it wont work. It basically selects the "wrong" item....the item that would be in that place if the scrollbar was all the way up....VB Code:
Private Sub listOnline_MouseDown(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) Handles listOnline.MouseDown If e.Button = Windows.Forms.MouseButtons.Right Then Dim mouseY As Integer = listOnline.PointToClient(Windows.Forms.Cursor.Position).Y Dim itemIndex As Integer = (mouseY \ listOnline.ItemHeight) - listOnline.TopIndex listOnline.SelectedIndex = itemIndex listOnline.ContextMenuStrip = blockMenu Dim myString As String = listOnline.SelectedItem Dim mySplit(2) As String mySplit = Split(myString, " - ") If InStr(mySplit(0), "¤") Then Block.Text = "Unblock: " & mySplit(2) Else Block.Text = "Block: " & mySplit(2) End If End If End Sub
It probably has something to do with this:.....what could I use instead to make it work?VB Code:
Dim itemIndex As Integer = (mouseY \ listOnline.ItemHeight) - listOnline.TopIndex




Reply With Quote