Guidance on drawing and interacting with DateTimePickers matrix

curiouswebster
curiouswebster used Ask the Experts™
on
I was creating the attached dialog using a DataGridView, since this is clearly a matrix of controls. but I ran into numerous problems when embedding a DateTimePicker both to handle dates and times. SO I have abandoned that plan and now want an old fashioned set controls I can easily interact with, since they will be created on the form. But I need the rows added by the user to be an extensible list.

I need to grab Location.Y from the prior row, add n pixels and combine that with the same Location.X values from the previous row when determining the locations of each control.
That should be easy.  What will be new for me is creating those controls and coming up with a way to assign a unique ID for the controls.

How do I create events for these controls when I do not know their ID's at compile time?  Can I put the controls into a list so they can be refernced via their index in the list?  When using the DataGridView, each event had an e.RowIndex value and that worked fine.  But to repeat myself, I had so many event problems to still resolve. I think this would be quicker.

Please make suggestions or point me towards a demo program.

Notice on the attached image, when the user clicks Edit, in some cases I would need to remove the text field and replace that with a text edit field.  Any suggestions on that transformation would also be appreciated.


Question: Will a TableLayoutPanel be easier for me to manage drawing this matrix of controls without the hassles I have gotten from the DataGridView??

Thanks.
TimeArray.bmp
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
What I would do is to create a user control with all you need for a row. I would use a MultiView, with 2 views, one for add/edit mode and one for read-only mode.
Then you must have a list with your usercontrols, where you add/remove items. You should save the list in ViewState to have it available between posts.
Here's a basic example:
http://litemedia.info/dynamic-user-control-list

After you do this and everything is working fine you should try some Ajax - update panels to make it look better for the user, but this is another story.
Most Valuable Expert 2012
Top Expert 2008
Commented:
BTW, this is Windows Forms...

Where you trying to create a custom column type with a DateTimePicker in each cell for a column?  

How to: Host Controls in Windows Forms DataGridView Cells
http://msdn.microsoft.com/en-us/library/7tas5c80.aspx
curiouswebsterSoftware Engineer

Author

Commented:
Sorry, this is WinForms. I forgot to mention that in the post.  

Yes, I am trying to get the DateTimePickers working in a DataGridView.  I will check out the link this morning.

Thanks.
curiouswebsterSoftware Engineer

Author

Commented:
Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial