Hello friends.
that's gr88 that you people help out alot. My senerio is .. i made data grid form ..where i want ... when i double click on a Invoice no ... or Row in datagrid .. invoice open in new form where i can edit delete, or other opraitons with invoice..
i know how to edit in same form ... through .. SelectedRows .. method
Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
Dim obj As DataGridViewSelectedRowCollection = DataGridView1.SelectedRows
txtHotelId.Text = obj.Item(0).Cells(0).Value
txtHotelName.Text = obj.Item(0).Cells(1).Value
txtContactPerson.Text = obj.Item(0).Cells(2).Value
txtLocation.Text = obj.Item(0).Cells(3).Value
txtPhone.Text = obj.Item(0).Cells(4).Value
TxtFax.Text = obj.Item(0).Cells(5).Value
txtEmail.Text = obj.Item(0).Cells(6).Value
txtAddress.Text = obj.Item(0).Cells(7).Value

End Sub

5 Years
Discussion Span
Last Post by saleem.mukhtiar

well , you can do this by declaring a global variable , named invoiceno , and then get the value of invoice from the grid and use that value at the new form load event , for example you have two forms , frmchoose , frmshow, and a global variable name invoiceno. now use this code.

'at the double click of your grid
invoiceno = datagrid.item(0,datagrid.currentrow.index).value.tostring()

'now assume you have a query through which you are filtrng records , now do like this
sql = "select * from sales where invoiceno="& invoiceno

may be this will solve your prob


You went to right direction saleem, but you should only use DataGridViewRow class.
Why? You cannot select more then 1 row, since you only have 1 textBox for each column (so array of rows drops off here).
You can do:

Dim row As DataGridViewRow = dataGridView1.SelectedRows(0)
txtHotelId.Text = row.Cells(0).Value.ToString()
txtHotelName.Text = row.Cells(1).Value.ToString()
txtContactPerson.Text = row.Cells(2).Value.ToString()
txtLocation.Text = row.Cells(3).Value.ToString()
txtPhone.Text = row.Cells(4).Value.ToString()
TxtFax.Text = row.Cells(5).Value.ToString()
txtEmail.Text = row.Cells(6).Value.ToString()
txtAddress.Text = row.Cells(7).Value.ToString()

Mitja Bonca Dear My code working perfect.. but its in same form .. i want to show in a new form ... or dailog box .. :)
and budnle of thanx for your times brothers ... Waqas and Mitja Bonca


I see, sorry.
On new form put textboxes. On form where DGV is, create an array of data (of selected row) and paste to new form and show data from array in textBoxes.

Dim data() As String = New String((dataGridView1.Columns.Count) - 1) {}
For Each row As DataGridViewRow In dataGridView1.SelectedRows
    Dim i As Integer = 0
    Do While (i < row.Cells.Count)
        data(i) = row.Cells(i).Value.ToString
        i = (i + 1)
    Exit For
    'only 1st selected row will be used (you can remove it)
Dim f2 As Form2 = New Form2(data)
'on form2:
Class Form2
    Public Sub New(ByVal data() As String)
        textBox1.Text = data(0)
        'and so on...
    End Sub
End Class
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.