I have 2 DGV. In first DGV (DGV1), I am entering the Item Name in Column(1). (Based on Item Name other cells in this DGV1 will be populated and this part is running fine).
2nd DGV (DGV2) is linked to Database containing Item Names, Item Groups. While working in DGV1 - columns1, I want to see and select the Item Names from this DGV2. (i.e. DGV2 is just an assistant DGV)
For this I made program to show DGV2 as soon as Cursor enters the Column1 of DGV1 (It will hide as soon as item is selected). And Now I want that values in DGV2 get filtered depending upon Text typed in DGV1.Column1 and additionally, if any time, the text entered in column1, results in DGV2 blanking (i.e. filtered result count = 0) then that particular last word must be cancelled (like e.handled = true).
My program captures the first Letter Typed in DGV and search command in DGV2 is running OK but when another letter is typed, it do not concatenate the word already typed in Cell with New Letter typed. Please help. (In debugging I noticed that DGVRow.Cells(1).Value is always nothing even after some keys are typed in)
I successfully done similar task using Textbox in place of DGV1, I used TextBox.textchanged event to capture the text typed in Textbox. But in case of DGV, as there is no direct Cell.textchanged event and hence I am facing challenge in capturing the Text being typed in DGV1.column1.
Code working when using Textbox is as under –
[Code]
Private Sub Textbox1_TextChanged(sender As Object, e As EventArgs) Handles Textbox1.TextChanged
If DGV2.RowCount > 0 Then ‘ DT is datasource of DGV2
ElseIf DGV2.RowCount = 0 ThenTextbox1.Text = Textbox1.Text.Substring(0, Textbox1.Text.Length - 1)
Textbox1.Select(Textbox1.Text.Length, 0)
End If
End Sub
[Code\]
Code I tried with DGV is as under.
[Code]
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
Dim Keycode As Integer = CType(keyData, Integer)
Dim MyKey As Keys = CType(Keycode, Keys)
If ActiveControl.GetType Is GetType(DataGridViewTextBoxEditingControl) OrElse ActiveControl Is DGV1 ThenDim DGV As DataGridView = Nothing
If ActiveControl.GetType Is GetType(DataGridViewTextBoxEditingControl) ThenDim DGVTEIC As DataGridViewTextBoxEditingControl = CType(ActiveControl, DataGridViewTextBoxEditingControl)
DGV = CType(DGVTEIC.EditingControlDataGridView, DataGridView)
ElseDGV = CType(ActiveControl, DataGridView)
End If Dim DGC As DataGridViewTextBoxCell = DGV.CurrentCell
If IsNothing(DGC) Then Return MyBase.ProcessCmdKey(msg, keyData)
If AlphanumericKeys.IndexOf(Chr(keyData)) >= 0 Then
Dim DGVRow As DataGridViewRow = DGVItmDetail.Rows(nRow)
Dim searchstr As String = DGVRow.Cells(1).Value + MyKey.ToString
‘ Here SearchString must be a Combination of Text already in Cell and New Typed key BUT DGVRow.Cells(1).Value is always Nothing as per Debugging
DT.DefaultView.RowFilter = "ItmName LIKE '*" & searchstr & "*' "
If DGV2.RowCount > 0 Then
ElseIf DGV2.RowCount = 0 Thensearchstr = searchstr.Substring(0, searchstr.Length - 1)
DT.DefaultView.RowFilter = "ItmName LIKE '*" & searchstr & "*' "
Return True
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End If
End If
End Function
[Code\]