Results 1 to 4 of 4

Thread: Search to run in DGV2 based on Text Typed in DGV1's Column

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2022
    Posts
    15

    Search to run in DGV2 based on Text Typed in DGV1's Column

    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
    DT.DefaultView.RowFilter = "sItemName LIKE '*" & Textbox1.Text.TriQuery on Search in DGV.docxm & "*' "

    If
    DGV2.RowCount > 0 Then ‘ DT is datasource of DGV2

    ElseIf DGV2.RowCount = 0 Then
    Textbox1.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 Then
    Dim DGV As DataGridView = Nothing
    If ActiveControl.GetType Is GetType(DataGridViewTextBoxEditingControl) Then
    Dim DGVTEIC As DataGridViewTextBoxEditingControl = CType(ActiveControl, DataGridViewTextBoxEditingControl)
    DGV = CType(DGVTEIC.EditingControlDataGridView, DataGridView)
    Else
    DGV = 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 Then
    searchstr = 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\]
    Last edited by Keerti; Sep 12th, 2022 at 09:21 AM. Reason: Code Formatting and attached the query as word doc with proper formatting

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Search to run in DGV2 based on Text Typed in DGV1's Column

    Please format your code properly.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2022
    Posts
    15

    Re: Search to run in DGV2 based on Text Typed in DGV1's Column

    Quote Originally Posted by jmcilhinney View Post
    Please format your code properly.
    I tried to upload the Code via Word doc so that it get copied with Formatting but without success. so I have done some formatting manually. Additionally attached the Query in word document, which I hope shall give better readability.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Search to run in DGV2 based on Text Typed in DGV1's Column

    Or you could just paste it inside CODE tags, like everyone else does.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width