views:

187

answers:

1

Hi,

I want to create a table representing data I have, but I want each row to have a custom display. I have developed a little custom control that represents a row and has a few items in it (text box, check box, progress bar), however how do I now in the main form create multiple instances of this for the data I have?

e.g. is there a winforms control I can use to do this? or do I have to take a panel or something and programmatically do it?

I do need to somehow take responses back. So if someone clicks on the button in the 4th row say then I'll need to be able to tell which row it was from.

As an aside would then be a way to BIND the above mentioned visualization of my data to the data itself, say housed in an Array?

thanks

+3  A: 

I see two options here:

  • You can use a DataRepeater. This control can be found in the Microsoft Visual Basic Powerpack. It allows you to place controls on a template which gets copied for each item in the databound collection.
  • You can create a custom control and manually place one instance of it for each item in a collection, re-creating databinding for the controls in it. This requires you to either expose the controls inside publicly or as properties of the user control.

However, above options are mostly useful for non-tabular data. If your layout is strictly tabular (i. e. rectangular cells in a grid) then you can create a custom DataGridViewCell which takes some time to understand but not too much code. Putting a progress bar into such a cell shouldn't prove too difficult.

Joey
tks - re the DataRepeater, could I use this in a c# project? Would this be the easier option do you think?
Greg
Yes, you can. Using `DataRepeater` would probably be easier.
SLaks
Well, we had some problems with focus and databinding (and therefore updates of the databound values). Generally I didn't find the control to be too pleasant but re-creating the same functionality from scratch is ... work. I found the custom control + FlowLayoutPanel to be easier to handle, especially regarding tab order and such detail stuff (for example, the DataRepeaterItem always can get focus which was undesirable there).
Joey
ok Johannes - so I should have a good into the FlowLayoutPanel too...I see it's one of the existing controls in VS2008 so it should be solid I guess
Greg
It's more work, though. Try out the DataRepeater which shouldn't take as long. See if you like it. As for me, I didn't like it but YMMV.
Joey
OK - out of curiosity would moving to WPF make this an easier thing to deal with? i.e. the ability to have a customized table with each row looking just like you want it to?
Greg
Much easier, actually. In fact, in WPF every ItemsControl (such as ListBox, ComboBox, Menus, etc.) is an implicit DataRepeater.
Joey