Problem with Datagridview and BindingNavigator in vb.net 2.0
Hi,
I have a rewquirement in my Appln.
ie..
in my appln, In 1st form i have a datagridview Control,In 2nd form I have a BindingNavigator control.
When i press a next button in bindingNavigator, I have to display the selected row fields of datagridiew contol of form1, in Text boxes of 2nd form.
Please help me.
My thought here is whether this is a one way process to display the contents in a separate form but one way I would approach is to have a property on form2 which is a datarow.
On the first form - you have a reference to the form2 (x) and you can then pass the current row to the form2 property when the BindingSource1 control event indicates a change in the current record.
FORM1
Public Class Form1
Dim dt As New DataTable
Dim x As Form2 = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'//Create Datatable to bind against
dt.Columns.Add("col1")
dt.Columns.Add("col2")
dt.Rows.Add(1, "col1")
dt.Rows.Add(2, "col2")
dt.Rows.Add(3, "col3")
dt.Rows.Add(4, "col4")
'//Create a 2nd form to show details
If x Is Nothing Then
x = New Form2
x.Show()
End If
'//Bind the datatabole to the binding source and datagridview
Me.BindingSource1.DataSource = dt
Me.DataGridView1.DataSource = Me.BindingSource1
End Sub
Private Sub BindingSource1_BindingComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.BindingCompleteEventArgs) Handles BindingSource1.BindingComplete
Update2ndForm()
End Sub
Private Sub BindingSource1_CurrentChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingSource1.CurrentChanged
Update2ndForm()
End Sub
Sub Update2ndForm()
'//Pass the current row to a property on the 2nd form
If x IsNot Nothing AndAlso Me.BindingSource1.Current.row IsNot Nothing Then
CType(x, Form2).dr = Me.BindingSource1.Current.row
End If
End Sub
End Class
FORM2
Public Class Form2
Private _dr1 As System.Data.DataRow
Public Property dr() As System.Data.DataRow
Get
Return _dr1
End Get
Set(ByVal value As System.Data.DataRow)
_dr1 = value
If _dr1 IsNot Nothing Then
Me.TextBox1.Text = _dr1.Item(0).ToString
Me.TextBox2.Text = _dr1.Item(1).ToString
End If
End Set
End Property
End Class