Pls guide how to search the data in grid on text change event ..
Code:Private Sub txtSearchName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearchName.TextChanged ''Move the cursor to the position -- if sigle word is match 'lblSearch.Text - Column Name in which the Search should be done Dim intLoop As Integer Dim intLength As Integer Dim intRowFound As Integer intRowFound = 0 intLength = Len(txtSearchName.Text) If dgvDisplay.RowCount > 1 Then For intRowFound = 1 To dgvDisplay.RowCount - 1 If LCase(txtSearchName.Text) = LCase(Mid(dgvDisplay.Rows(intLoop).Cells(Trim(lblSearch.Text)).Value, 1, intLength)) Then intRowFound = intLoop dgvDisplay.Rows.SharedRow(intRowFound) dgvDisplay.Rows.GetRowState(intRowFound) dgvDisplayBindingSource.Position = intRowFound Exit Sub Else dgvDisplay.Rows.SharedRow(intRowFound) dgvDisplay.Rows.GetRowState(intRowFound) dgvDisplayBindingSource.Position = intRowFound End If Next End If ''Match the txtsearchname.text with grid value and then move to position 'Try ' Dim Rows As DataRow() = DtDisplay.Select(String.Format("{0} LIKE '{1}*'", Trim(lblSearch.Text), Trim(txtSearchName.Text)), dgvDisplayBindingSource.Sort) ' If Rows.Length > 0 Then ' Dim FoundIndex As Integer = dgvDisplayBindingSource.Find(Trim(lblSearch.Text), txtSearchName.Text) ' dgvDisplayBindingSource.Position = FoundIndex ' End If 'Catch ex As Exception ' MsgBox(ex.Message) 'End Try End Sub




Reply With Quote