C#Newbie01

I believe this would be a Data Binding Question. I have read up on it a lot, but have not been able to find an answer to my question (Though I see programs that work like I would like mine to, so I know it's possible).

I have a dataGridView, which loads some information from my Access 2007 Database. The dataGridView is on my main form and works great thus far.

I also have another form with a bunch of textBoxes, etc. on it.

I would like to, when I click on a line of the dataGridView, it opens the second form (The one with the textBoxes), and loads the data for that particular item / row in the textBoxes and other controls.

How would I go about doing this I have really had no luck with this whatsoever. I would post my code, but there isn't a heck of a lot of it, and I think at this point it probably just makes more sense to start from scratch here...

Thank you very much for any and all help.


Re: Windows Forms Data Controls and Databinding Data Binding Question?

ahmedilyas

Basically, you need to pass the DataRow of that Row you clicked on (Entered). So on the RowEnter event of the dataGridView, you would then open the other form and pass the Row of data from the datasource.

If your data source is a DataTable, then pass that row of the DataTable to the constructor of the second form, so it can then populate the form correctly with values from that DataRow your passed into the form's constructor, then show the form.

You could also pass the DataGridViewRow if you like, whichever you feel comfortable with.

In the RowEnter event, the DataGridViewCellEventArgs parameter has a RowIndex property, this will then give you the current row you clicked on which you can use to get the index of the row from the DataTable, or the DataGridView.

Does this help Does it give you any hints/tips :-)






Re: Windows Forms Data Controls and Databinding Data Binding Question?

C#Newbie01

Hello and thank you very much for your response.

I am very sorry, your post sounds very helpfull, but a lot of it kind of went over my head. It really sounds like it answers my questions, but I can't quite seem to wrap my head around what you're saying. Would you mind dumbing it down a bit for me lol...

Every so often in learning software development I come across something that I kind of have a hard time coming to grips with, and I'm affraid DataBinding and such is going to be one of them...

Thank you very much.




Re: Windows Forms Data Controls and Databinding Data Binding Question?

C#Newbie01

I was reading up some more on this to hopefully find a way in which I could do this, and can't seem to find a reference that puts things in words I can understand. How would I go about doing this I created a RowEnter event, but am not sure what the code should look like to take the data for that item and pass it to the next form. I'm also unsure of how I would get the data to populate the appropriate textBoxes and such on the other form.

I'm sorry, but I just don't understand this. I have 2 books that cover Data Binding, and I read both of them, but don't quite understand this.

I really appreciate any help anyone can give me. I would love to be able to get this working.

Thank you very much.




Re: Windows Forms Data Controls and Databinding Data Binding Question?

Rong-Chun Zhang - MSFT

Hi C#Newbie01,

I find a code sample for your reference. Below is the link:

http://www.codeproject.com/cs/database/IEditableObject.asp

This sample use a button click event to open the second form, you may need replace it with a DataGridView.CellClick event.

Hope this helps.

Best regards.