开发者

What is the best way to embed controls in a list/grid

I have a table of about 450 rows that I would like to display in a graphical list for users to view or modify the line items. The users would be selec开发者_开发问答tion options from comboboxes and selecting check boxes etc.

I have found a listview class that extends the basic listview to allow for embeding objects but it seems kind of slugish when I load all the rows into it.

I have used a datagridview in the past for comboboxes and checkboxes, but there was a lot of time invested in getting that up and running...not a big fav of mine.

I am looking for sugestions how I can do this with minimal overhead.

thanks

c#, vs2008, .net 2.0, system.windows.forms


If you have a complicated set of controls for each row, this is the simplest way to do it. However, it won't act like a listbox; you won't be able to highlight your rows or navigate with the keyboard.

  • Create a usercontrol with public property to point to your row
  • Draw a panel on your form - you will add instances of your 'row' usercontrol at runtime to this panel.
  • Set the panel to autoscroll (also set property to make the active control scroll into view)
  • Set the panel's Anchor property so it sizes w/ the window
  • You can set the form's max/min size properties so the full usercontrol row always shows (have to do to prevent horiz. scroll bar in panel)
  • Have a routine to add the rows
  • In a loop, create new usercontrols, set their properties, including the row in the datatable
  • Also, set the .Top property to the panel's .controls(pnl.controls.count-1) for all but the first one you add

Very simple, allows complicated 'rows', gets the job done. There are better ways to do this if you want listbox-like functionality without coding it yourself, but you may not need that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜