Select 下一个重复的列表框 item.net
Select Next duplicate Listbox item.net
我试了几次,到Select下一个重复行,并同时更改它,
例如,
ListBox1 item's :
1
1
1
2
1
3
4
5
我的代码(按钮 1):
By that it will change First "1" in top line, next , it will select
another "1" and will change it too , To "Changed" ... Etc.
If TextBox1.Text = "1" Then
ListBox1.SelectedItem = TextBox1.Text
Dim indx As Integer = ListBox1.SelectedItem
If indx <> -1 Then
ListBox1.Select(indx, TextBox1.Text.Length
If ListBox1.SelectedItem <> "" Then
ListBox1.SelectedIndices = "Changed"
End If
End If
End If
我试过了,但是它 select 编辑了所有重复的项目,我希望每个按钮点击一次 select。
Dim s As String = Me.TextBox1.Text
Dim lb As ListBox = Me.ListBox1
lb.SelectedIndex = -1
If s.Length <> -1 Then
For i As Integer = 0 To lb.Items.Count - 1
Try
If lb.Items(i).ToString.Contains(s) Then
lb.SelectedIndices.Add(i)
Else
End If
Catch ex As Exception
End Try
Next
End If
每个按钮 1 次点击都会更改 1 个重复的项目行。
我不确定我是否理解您的需求,但试试这个:
Dim s As String = Me.TextBox1.Text
Dim lb As ListBox = Me.ListBox1
Dim selected = lb.SelectedIndex
If s.Length <> -1 Then
For i As Integer = selected + 1 To lb.Items.Count - 1
If lb.Items(i).ToString = s Then
lb.SelectedIndex = i
Exit For
End If
Next
End If
我试了几次,到Select下一个重复行,并同时更改它,
例如,
ListBox1 item's :
1
1
1
2
1
3
4
5
我的代码(按钮 1):
By that it will change First "1" in top line, next , it will select another "1" and will change it too , To "Changed" ... Etc.
If TextBox1.Text = "1" Then
ListBox1.SelectedItem = TextBox1.Text
Dim indx As Integer = ListBox1.SelectedItem
If indx <> -1 Then
ListBox1.Select(indx, TextBox1.Text.Length
If ListBox1.SelectedItem <> "" Then
ListBox1.SelectedIndices = "Changed"
End If
End If
End If
我试过了,但是它 select 编辑了所有重复的项目,我希望每个按钮点击一次 select。
Dim s As String = Me.TextBox1.Text
Dim lb As ListBox = Me.ListBox1
lb.SelectedIndex = -1
If s.Length <> -1 Then
For i As Integer = 0 To lb.Items.Count - 1
Try
If lb.Items(i).ToString.Contains(s) Then
lb.SelectedIndices.Add(i)
Else
End If
Catch ex As Exception
End Try
Next
End If
每个按钮 1 次点击都会更改 1 个重复的项目行。
我不确定我是否理解您的需求,但试试这个:
Dim s As String = Me.TextBox1.Text
Dim lb As ListBox = Me.ListBox1
Dim selected = lb.SelectedIndex
If s.Length <> -1 Then
For i As Integer = selected + 1 To lb.Items.Count - 1
If lb.Items(i).ToString = s Then
lb.SelectedIndex = i
Exit For
End If
Next
End If