Hello guys
I am trying to pass values from a 2nd form to main form, and to certain extends I have managed the stuffs. However, Once the values are passed to the datagridview of the main form, I want to move the focus to a certain column and that is not happening.
Please refer the image for the approach
and the code behind with form2.vb as below
I know I cannot set the focus to the desired cell because the control is not initialized. Please explain me how to!Code:Public Class Form2 Private f1 As Form1 Public Sub New(ByRef f As Form) InitializeComponent() Me.f1 = f End Sub Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim dt As DataTable = New DataTable dt.Columns.Add("itemid") dt.Columns.Add("itemname") dt.Rows.Add(1000, "isceon 22/50") dt.Rows.Add(1001, "Freon 22/50") dt.Rows.Add(1002, "Mafatlal 22/50") dt.Rows.Add(1003, "Access Value 1/4") dt.Rows.Add(1004, "Compressor 5hp") DataGridView1.DataSource = dt End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'If (f1.DataGridView1.CurrentRow.IsNewRow) Then ' Dim cell As DataGridViewCell = f1.DataGridView1.CurrentRow.Cells("itemid") ' DataGridView1.CurrentCell = cell ' DataGridView1.BeginEdit(True) 'End If f1.DataGridView1.CurrentRow.Cells("itemid").Value = Me.DataGridView1.CurrentRow.Cells("itemid").Value f1.DataGridView1.CurrentRow.Cells("itemname").Value = Me.DataGridView1.CurrentRow.Cells("itemname").Value End Sub End Class
Please help!
regards,




Reply With Quote
