I am working with a tabbed form. On the first tab I have a datagridview with customers in it and a searching textbox. I have that working. On the second tab I am placing another datagridview with customer transactions and other data. The customer transaction table has a CustomerID Column which matches the key column in the Customer table on which the first datagridview is based. I am trying to save the key column value in a textbox so that I can use it to filter the datagridview in the second tab.

I can fill in the textbox that contains the key field from a search from another text box on the form. However, if the user does a partial search (example. types in 'Wil' and it returns a record with Williams when the user is actually looking for Wilson. The user would then be able to scroll down and click on the record with wilson). It is here that I am having trouble returning the key field and placing it in the text box.

I know this has to be simple, but I am new to vb.net. My previous experience is in VBA. I am presently reworking an application I did in VBA.

I have figured out the code. Here it is. I know there is probably something simpler but this works for me.

Private Sub DataGridView1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick
        Dim rowClicked As Integer

        If e.Button = Windows.Forms.MouseButtons.Left Then
            rowClicked = DataGridView1.HitTest(e.Location.X, e.Location.Y).RowIndex
            For Each gRow As DataGridViewRow In DataGridView1.Rows
                If gRow.Index = rowClicked Then
                    Me.TextBox2.Text = DataGridView1.Rows(rowClicked).Cells(0).Value

                End If

        End If
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.