|
-
Sep 10th, 2006, 05:31 AM
#1
Thread Starter
Junior Member
[2005] data from datagridview to new form?!
Hi, all!
I want to make an application where user can click on datagridview row and new form opens. New form will contain textboxes where all data will be loaded... first step, of course, is making dblclick event on table, and open new form... I have made it trough so far... what should I do next?
-
Sep 10th, 2006, 06:19 AM
#2
Re: [2005] data from datagridview to new form?!
You should show us your code. This problem should be broken down into three distinct parts:
1. Handle the DoubleClick event of the grid.
2. Get the data for the current row in the grid.
3. Open a form and pass data to it.
These are three separate, unrelated problems and you should treat them as such. Once you've solved all three of those problems you can simply put them together and you've solved your original problem. That's called "divide and conquer". Can you do those three things? If not, which parts are you having an issue with? Remember, you should tackle each sub-problem first without worrying about how it fits into the bigger picture.
-
Sep 11th, 2006, 03:20 AM
#3
Thread Starter
Junior Member
Re: [2005] data from datagridview to new form?!
I just dont have any idea how to pass data to another form... thats where the problem is
-
Sep 11th, 2006, 04:22 AM
#4
Re: [2005] data from datagridview to new form?!
You should read the "Forms in VB.NET" tutorial in my signature.
Forms are objects like any other in VB.NET. If you wanted to pass data to some other object what would you do? You'd set a property or call a method and pass a parameter. Forms are objects so you do exactly the same thing to pass data to a form. You can pass a DataTable, a DataRow or individual field values. Because it's your form it's up to you to write these properties or methods that you will call. That's not a problem though. You write properties and methods all the time and this is no different. Note that class constructors are methods too, and that's a good place to pass data to a form that every instance will need.
-
Sep 11th, 2006, 05:21 AM
#5
Thread Starter
Junior Member
Re: [2005] data from datagridview to new form?!
so now I can pass data from one textbox to another, thats kinda cool... question - how can I take data from row.. For example - if I have an table with columns "Date, time, action", how can I load them into textboxes so, that textbox1 would display "date" cell value, textbox2 - time value, etc?
-
Sep 11th, 2006, 05:37 AM
#6
Re: [2005] data from datagridview to new form?!
You should pass the bound row and get your data from that. If you have bound a DataTable through a BindingSource, as I recommend that you do, then the BindingSource.Current property will retrun a reference to a DataRowView object for the current row. To get the value from a particular column you simply do this:
VB Code:
Dim row As DataRowView = DirectCast(myBindingSource.Current, DataRowView)
MessageBox.Show(row("ColumnName"))
That's one of the reasons that it'sa good idea to use a BindingSource: because it makes getting at the bound data much easier. When the user selects a row in the grid you can get the bound data from the BindingSource using the first line above without worrying about indexes or anything like that. You'd then pass that DataRowView to your second form and it would get the individual fields as done in the second line above. If the user makes changes you simply assign the new values to the fields again and your grid AND bound DataTable will update automatically. If anyone tells you that data-binding is a bad thing then they don't know how to use it properly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|