Finding text from the datagrid view in vb.net

后端 未结 3 1175
醉酒成梦
醉酒成梦 2021-01-21 09:58

I have a data grid view in one windows form named \"GridViewForm\". When the user search for the text from the search box from another window form named \"FindForm\", I want to

3条回答
  •  不知归路
    2021-01-21 10:25

    You could use String.contains instead of an =.

    Here is the MSDN article on the contains method:

    http://msdn.microsoft.com/en-us/library/dy85x1sa.aspx

    code to style the cell if it contains the search text:

        Dim someText As String = SearchTextBox.Text
        Dim gridRow As Integer = 0
        Dim gridColumn As Integer = 0
        For Each Row As DataGridViewRow In AccountsDataGridView.Rows
            For Each column As DataGridViewColumn In AccountsDataGridView.Columns
                Dim cell As DataGridViewCell = (AccountsDataGridView.Rows(gridRow).Cells(gridColumn))
                If cell.Value.ToString.ToLower.Contains(someText.ToLower) Then
                    cell.Style.BackColor = Color.Yellow
                End If
                gridColumn += 1
            Next column
            gridColumn = 0
            gridRow += 1
        Next Row
    

提交回复
热议问题