please help !!!!
-
sorry i explained the query wrong. i need to use a button to replace the selected item with the one above, and do the same with the one below. i suppose this code could be modified a bit but dont know how. can anyone help me please. Select Previous: ListBox1().SelectionMode = SelectionMode.One If Me.ListBox1.SelectedIndex > 0 Then Me.ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex - 1 End If Select Next: ListBox1().SelectionMode = SelectionMode.One If Me.ListBox1.SelectedIndex < Me.ListBox1.Items.Count - 1 Then Me.ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex + 1 End If
-
sorry i explained the query wrong. i need to use a button to replace the selected item with the one above, and do the same with the one below. i suppose this code could be modified a bit but dont know how. can anyone help me please. Select Previous: ListBox1().SelectionMode = SelectionMode.One If Me.ListBox1.SelectedIndex > 0 Then Me.ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex - 1 End If Select Next: ListBox1().SelectionMode = SelectionMode.One If Me.ListBox1.SelectedIndex < Me.ListBox1.Items.Count - 1 Then Me.ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex + 1 End If
-
sorry i explained the query wrong. i need to use a button to replace the selected item with the one above, and do the same with the one below. i suppose this code could be modified a bit but dont know how. can anyone help me please. Select Previous: ListBox1().SelectionMode = SelectionMode.One If Me.ListBox1.SelectedIndex > 0 Then Me.ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex - 1 End If Select Next: ListBox1().SelectionMode = SelectionMode.One If Me.ListBox1.SelectedIndex < Me.ListBox1.Items.Count - 1 Then Me.ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex + 1 End If
oh i think i understand, you want the selected item on button press to have the same value as the next or previous item. If that is the case: Make sure your listbox selectionmode = selectionmode.multiextended Select all:
ListBox1().SelectionMode = SelectionMode.MultiExtended For i As Integer = 0 To Me.ListBox1.Items.Count - 1 Me.ListBox1.SetSelected(i, True) Next
Change current to same as previous:ListBox1().SelectionMode = SelectionMode.One Dim Selected As Integer = Me.ListBox1.SelectedIndex Dim newItem As String If Me.ListBox1.SelectedIndex > 0 Then newItem = Me.ListBox1.Items.Item(Selected - 1) Me.ListBox1.Items.RemoveAt(Selected) Me.ListBox1.Items.Insert(Selected, newItem) Me.ListBox1.SelectedIndex = Selected End If
Change current to same as next:ListBox1().SelectionMode = SelectionMode.One Dim Selected As Integer = Me.ListBox1.SelectedIndex Dim newItem As String If Me.ListBox1.SelectedIndex < Me.ListBox1.Items.Count - 1 Then newItem = Me.ListBox1.Items.Item(Selected + 1) Me.ListBox1.Items.RemoveAt(Selected) Me.ListBox1.Items.Insert(Selected, newItem) Me.ListBox1.SelectedIndex = Selected End If
Posted by The ANZAC