I have two DataGridViews in one window. The first one displays 2 columns, itemNo and task. When I click on a row in this grid, I want to populate the second grid with corresponding material. It is organized so that the itemNo in grid1 is 1, 2, 3, and so on, and so when a row is clicked, I want grid2 to show data that is 1.0, 1.1, 1.2, 2.0, 2.1 and so on. This data is all available in a table that exists within a dataset. However, tableAdapters do not use the .StartsWith function. I am able to get the information from grid1 when it is clicked on using Me.DataGridView1.CurrentRow.Cells(0).Value.ToString but how can I use this to get the data from the table into grid2?


So it turns out that I was not able to find ANYTHING that would help with this. Since I'm getting toward the end of this project, I've been chugging away at this for about 6.5hrs now. Here is what I have that works...

Instead of two dataGridViews, I am using two labels and one datagrid view. The two labels display the information, while the gridview shows the corresponding data. I use "Next" and "Back" buttons to move through the table and adjust the labels, while the gridview is cleared/populated each time. Here is the code:


            Me.item = Me.item + 1
            Me.lblPerItemNo.Text = tblTraining.Rows(Me.item).Item("itemNo").ToString
            Me.lblPerTask.Text = tblTraining.Rows(Me.item).Item("task").ToString

            If Me.tblTraining.Rows(Me.item + 1).Item("itemNo").ToString.StartsWith(Me.lblPerItemNo.Text) Then
                Me.item += 1
                DataGridView1.Rows.Add(New String() {tblTraining.Rows(Me.item).Item("ques1").ToString, tblTraining.Rows(Me.item).Item("ques2").ToString, tblTraining.Rows(Me.item).Item("ques3").ToString})
                GoTo checkme
            End If

If there is anyone with a suggestion to improve, or a different better way, please let me know. I'm open to any/all suggestions!

Be a part of the DaniWeb community

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