R
Richard Bond
I'm having a lot of trouble programatically selecting a listview item. How
do you do this?
These didn't work for me in the context of the sub below (that's trying to
move up an Item in the listview)
MeasView.Items(ItemIndex - 1).Selected = True
MeasView.Items(ItemIndex - 1).Focused = True
I would really appreciate some help.
thank you,
Rich
Private Sub MoveUpButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MoveUpButton.Click
Dim ItemIndex As Integer
Select Case MeasView.SelectedIndices.Count
Case 0
MessageBox.Show("You must select a measure to move first")
Case Is > 1
MessageBox.Show("You must select just one measure to move")
Case 1
'Find the item and check it's index
ItemIndex = MeasView.SelectedIndices.Item(0)
If ItemIndex = 0 Then
MessageBox.Show("You can't move this item up any more")
Else
MeasView.Items(ItemIndex).Text = (ItemIndex -
1).ToString.PadLeft(2, "0")
MeasView.Items(ItemIndex - 1).Text =
(ItemIndex).ToString.PadLeft(2, "0")
MeasView.Sorting = SortOrder.None
MeasView.Sorting = SortOrder.Ascending
MeasView.Items(ItemIndex - 1).Selected = True
MeasView.Items(ItemIndex - 1).Focused = True
End If
End Select
End Sub
do you do this?
These didn't work for me in the context of the sub below (that's trying to
move up an Item in the listview)
MeasView.Items(ItemIndex - 1).Selected = True
MeasView.Items(ItemIndex - 1).Focused = True
I would really appreciate some help.
thank you,
Rich
Private Sub MoveUpButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MoveUpButton.Click
Dim ItemIndex As Integer
Select Case MeasView.SelectedIndices.Count
Case 0
MessageBox.Show("You must select a measure to move first")
Case Is > 1
MessageBox.Show("You must select just one measure to move")
Case 1
'Find the item and check it's index
ItemIndex = MeasView.SelectedIndices.Item(0)
If ItemIndex = 0 Then
MessageBox.Show("You can't move this item up any more")
Else
MeasView.Items(ItemIndex).Text = (ItemIndex -
1).ToString.PadLeft(2, "0")
MeasView.Items(ItemIndex - 1).Text =
(ItemIndex).ToString.PadLeft(2, "0")
MeasView.Sorting = SortOrder.None
MeasView.Sorting = SortOrder.Ascending
MeasView.Items(ItemIndex - 1).Selected = True
MeasView.Items(ItemIndex - 1).Focused = True
End If
End Select
End Sub