Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with datagridview row to new detail form

Status
Not open for further replies.

tonygr

Technical User
Jan 20, 2005
42
GB
Hi all,
Sorry for asking such a newbie question,
I am using vs2005 and sql 2005 server
I have a form with a datagridview, and I want to double click a row and open a detail form.
Can anyone point me in the right direction for this.
Thanks in advance
Tony
 
Well you wont use a double click, it will be a single click.(whatever, right?)

Easy way:
You will need to setup another datasource on your form that takes a parameter as some value from the grid you are selecting. Then you tie a detail view to the datasource.

Hard way:
On the Selection change event of the datagrid dynamically create a datasource. Tie off to your database somehow. populate the detail view with the info returned from the database.



-The answer to your problem may not be the answer to your question.
 
Thanks for the pointers.
I have found some code see below, that does something along the lines of what I am after.

'DataGridView Form
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New DetailForm
'This assumes the GUID is in cell 0 which normally would not be displayed in the datagridview since it's value has no meaning to the user.
frm.Guid = DataGridView1.CurrentRow.Cells(0).Value
frm.Show()
End Sub


'Detail Form
Public Class DetailForm

Private myGuid As System.Guid

Public Property Guid() As System.Guid
Get
Return myGuid
End Get
Set(ByVal value As System.Guid)
myGuid = value
End Set
End Property


Private Sub DetailForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myTA As New myDSTableAdapters.TableNameAdapter
Dim myDT As New myDS.TableNameTable
myTA.FillBy(myDT, myGuid)

End Sub
End Class

I have tried to use the code within my project, but there are to many differences to correct, for example I am not using guid for a id column I am using simply numeric 18,0 with auto increment within the sql table, I would however like to say this is the ID column for the main records.
The forms I am using are searchaccident, which has the datagridview on it, also frmAddAccident, this form is also used to add a new row to the table addaccident, can it be used again for updating an existing record?
I have added a query =@idparam, getdataby1 to the table adapter ready for use in this part.

Sorry for the noobie qusetions also the explanation as to what I am trying to do. not very good at explaining what I want.
Thanks in advance
Tony G
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top