C# WinForms List / Detail Forms Help

theknight571

Platinum Member
Mar 23, 2001
2,896
2
81
I have a Windows Application written in C# with Visual Studio 2010. (I'm relatively new to this, I have been using mostly HTML/PHP for the past few years)

On one form I have a datagridview that displays basic fields (ID, name, request type, submission date) from a larger table.

What I am trying to do is allow the user to double click a row and have a request processing form come up so they can work the request.

The form with the datagridvew works properly, but I'm not sure how to setup the second (detail) form. So far all efforts have failed and Google keeps confusing me.

I have the doubleclick event setup and can get the data from the selected row necessary to display the proper data on the detail form, and even figured out how to pass that value to the new form, but I can't figure out how to build/setup/etc the detail form to get it to display the selected record.

Does anyone have any insight?

Also, if anyone has a good book for helping learn Visual Studio / C# / etc. let me know.

Thanks in advance.

Edit: I am now checking out the links in the reference thread.
 
Last edited:

brandonb

Diamond Member
Oct 17, 2006
3,731
2
0
This is what I do:

Use inheritance on the 2nd (detail) form. (I haven't used winforms in forever, I use WPF, so I apologize if this is not the right namespaces or syntax)

[source]
class clsNewForm : Inherit System.WindowForm
{

}
[/source]

Then add a property to that new class, that holds the information you want, which you set when you implement the double click.

Then override the OnLoad() event and place your logic that loads from that property and fills in all text boxes, etc.

(I hope this steers you into a direction that can help you solve the problem)

If you need a refresher on object orientation and inheritance check out this other thread:

http://forums.anandtech.com/showthread.php?t=2180936&highlight=

Unless I'm misunderstanding the issue. Are you looking for the detail form to update the original grid with the new values? That may require data binding.
 
Last edited:

theknight571

Platinum Member
Mar 23, 2001
2,896
2
81
Thanks for your help. I did review the link for an object oriented refresher.

It turns out that I was doing it correctly, but binding source/dataset/etc. was causing me problems by not displaying records with dates of '0000-00-00'.

It didn't generate any errors in the program itself, but when I went to Preview Data in the settings I got a date conversion error. After much digging I finally figured out it would display data for records with a proper date and not for those with '0000-00-00'.

So, I changed my default values for dates to null, instead of the zeros at the database... and it worked after that.

Storing the date as Null or '0000-00-00' doesn't make a difference at this point. :)

Thanks for your help.