469,903 Members | 2,027 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Using Double click on data grid to open another form

I have a vb.net datagrid bound to a dataview on a windows form. I want to
use the datagrid to display and filter a list of items, but since the data
is complex, I don't want the user to edit the item using the datagrid. I'd
like to have another form display when the user double clicks the desired
row in the datagrid, and have that form display details for the selected
datagrid row.

I'm having problems figuring out the best way to pass the selected row on
the first form to the second form. All of the data (including data from
related tables,) is already populated in the underlying dataset on the first
form, so I'd like to pass the dataset also. Can anyone recommend the best
and/or easiest way to accomplish this?

Thanks!
Nov 20 '05 #1
3 11561
Cor
Hi Young,

The most easy way I is to make a module and put the variables in that.
(Those are everywhere usable, in you whole project).

I don't do it I would make a class with shared properties
Witt that I can better see what I am doing.

Rough typed and just as an example
\\\
Public Class datagridinfo
private shared mA as string
private shared mB as string
Public shared property A as string
Get
return mA
End Get
Set (byval value as string)
mA = value
End set
Public Shared property B as String
.... same as A
end Class

Now you can say in form1
datagridinfo.A = mylineInFormA

And in form1
mylineInFormB = datagridinfo.A
////

I hope this helps a little bit

Cor


Nov 20 '05 #2
Cor
Mayby confusing the last part therefore this to correct
">
Now you can say in form1
datagridinfo.A = myItemInForm1

And in form2
myItemInForm2 = datagridinfo.A
Cor
Nov 20 '05 #3
Hello Young
Here is some code that does exactly that:

Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.DoubleClick

Dim MyGrid As DataGrid = DirectCast(sender, DataGrid)

Dim MyEdit As New UpdateAccountTypes(MyDataSet,
MyGrid.CurrentCell.RowNumber)

MyEdit.ShowDialog()

Me.DataGrid1.Refresh()

End Sub
This passes a dataset, and a row number based on the grid's
CurrentCellRowNumber

The Edit form's constructer (Sub New()) takes these two values as an
argument. Just write the code inthe form to handle your editing chores. Any
edit changes you make in the edit form will be reflected in the grid itself.
To make the changes persist, you'll have to update using the dataadapter for
that dataset.

Ibrahim
"Young J. Putt" <j.****@verizon.net> wrote in message
news:0L***************@nwrdny03.gnilink.net...
I have a vb.net datagrid bound to a dataview on a windows form. I want to
use the datagrid to display and filter a list of items, but since the data
is complex, I don't want the user to edit the item using the datagrid. I'd like to have another form display when the user double clicks the desired
row in the datagrid, and have that form display details for the selected
datagrid row.

I'm having problems figuring out the best way to pass the selected row on
the first form to the second form. All of the data (including data from
related tables,) is already populated in the underlying dataset on the first form, so I'd like to pass the dataset also. Can anyone recommend the best
and/or easiest way to accomplish this?

Thanks!

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by ratnakarp | last post: by
7 posts views Thread by Pam | last post: by
1 post views Thread by kingster | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.