因此,這裏是我的計劃看起來是什麼如何搜索ListBox中的文本?
什麼我想要做的就是搜索多少次也有一年級
這裏是代碼的朋友幫我做
Private Function countOccOfMark(ByVal mark As String)
Dim resultCount As Integer = 0
For cnt As Integer = 0 To lstDisplay.Items.Count - 1
Dim gradeMark As String = lstDisplay.Items(cnt)
Dim results() As String = gradeMark.Split(vbTab)
For Each res As String In results
If (res = mark) Then
resultCount = resultCount + 1
End If
Next
Next
Return resultCount
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim mark As String = InputBox("Enter a Grade to search for")
Dim amountFound As Integer = countOccOfMark(mark)
MessageBox.Show("Found " & amountFound & " Occurences of the mark " & mark)
End Sub
哪些工作正常,但我敢肯定有一個更簡單的方法來做到這一點
A)listview將允許您顯示在適當的列中的內容,以便您不需要拆分數據來檢查它。 2)一個持有名稱,等級百分比的類可以顯示如圖所示(使用'ToString()',但分開保存數據,所以你不需要拆分數據來檢查它 – Plutonix