Hello,
I have a problem with linking a datagridview to text boxes on a form.
I want to be able to click a row on the dgv and populate the fields of the associated form. Everything works fine, until I filter the dgv or sort it, at which point the relationship between the data on the dgv and the form is lost. I realise that this is because the first row in the dgv only relates to the first record in my dataset up until the point where I sort or filter the dgv, but what I can't get my head round is how to overcome this and achieve what I want to.
For the unsorted dgv, the code is simple...
My dataset includes a unique reference number (the "urn" column within the dataset) and I know that somehow I must be able to use this to achieve the result I want. After all, when I designed the dataset I thought the "urn" would come in handy, which is why I put it there. Perhaps it's just because it's late in the evening, but I can't figure it out.
In case you haven't guessed, I'm an amateur...
Any tips to resolve this would be greatly appreciated!
Thanks,
Tim
I have a problem with linking a datagridview to text boxes on a form.
I want to be able to click a row on the dgv and populate the fields of the associated form. Everything works fine, until I filter the dgv or sort it, at which point the relationship between the data on the dgv and the form is lost. I realise that this is because the first row in the dgv only relates to the first record in my dataset up until the point where I sort or filter the dgv, but what I can't get my head round is how to overcome this and achieve what I want to.
For the unsorted dgv, the code is simple...
VB.NET:
Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Click
intPtr = DataGridView1.CurrentRow.Index
Call usersubFillEntrantForm(intPtr)
End Sub
..
..
Public Sub usersubFillEntrantForm(ByVal index)
'sub to fill entrantControl with records from dataset
With eventdataDS.Tables("entrant").Rows(index)
EntrantControl1.urnLabel.Text = .Item("urn").ToString
EntrantControl1.surnameTextBox.Text = .Item("surname").ToString
EntrantControl1.firstnameTextBox.Text = .Item("firstname").ToString
..
End With
End Sub
My dataset includes a unique reference number (the "urn" column within the dataset) and I know that somehow I must be able to use this to achieve the result I want. After all, when I designed the dataset I thought the "urn" would come in handy, which is why I put it there. Perhaps it's just because it's late in the evening, but I can't figure it out.
In case you haven't guessed, I'm an amateur...
Any tips to resolve this would be greatly appreciated!
Thanks,
Tim