목록 상자 항목에있는 문자열을 읽고, 사용자에게 문자열을 입력하라는 메시지를 표시하고, 사용자가 올바르게 입력하면 선택할 항목이 남지 않을 때까지 다음 항목을 선택하는 방법이 있습니까? 나는 이것을 VB.NET에서 만들고있다. 도움을 주시면 감사하겠습니다.
다음과 같이 할 수 있습니다.
Dim items = ListBox1.Items.Cast(Of Object)().Select(Function(x) x >= x.ToString).ToList()
If items.Contains(TextBox1.Text) Then
Dim nextIndex = items.IndexOf(TextBox1.Text) + 1
If nextIndex < items.Count Then 'There is next item
Dim nextItem = items(nextIndex).ToString()
'Do something with your nextItem
End If
End If
기본적으로 다음 ListBox
을 수행 하여 모든 텍스트를 얻으려고합니다 .
Dim items = ListBox1.Items.Cast(Of Object)().Select(Function(x) x >= x.ToString).ToList()
그런 다음 입력 문자열이 ListBox의 텍스트에 있는지 확인합니다.
If items.Contains(TextBox1.Text) Then
.
.
.
End If
그렇다면 다음 항목의 색인을 얻습니다.
Dim nextIndex = items.IndexOf(TextBox1.Text) + 1
다음 항목의 인덱스가 ListBox
의 요소 수를 초과하지 않으면 다음 인덱스의 항목을 가져옵니다.
If nextIndex < items.Count Then 'There is next item
Dim nextItem = items(nextIndex).ToString()
'Do something with your nextItem
End If
다음 문자열은에 nextItem
있습니다.
또는 전체 항목 Where
을 채우지 않고 여전히 동일한 결과 를 얻으면 Codexer에서 제안한대로 추가 LINQ 절을 추가 할 수 있습니다 .
Dim item = ListBox1.Items.Cast(Of Object)().Select(Function(x) x >= x.ToString).Where(Function(y) y = TextBox1.Text).FirstOrDefault()
If Not item Is Nothing Then
Dim nextIndex = ListBox1.Items.IndexOf(item) + 1
If nextIndex < ListBox1.Items.Count Then 'There is next item
Dim nextItem = ListBox1.Items(nextIndex)
'Do something with your nextItem
End If
End If
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다