views:

182

answers:

3

I want to create a control which is basically a ListBox, but each ListItem is a collection of controls. So each item of that list box is a combination of a Label, a CheckBox, a Timer and a TextBox.

Can this be done with the .NET framework?

If so, do you have any recommendations on how to get started, any links to samples or discussion, or any open-source examples?

A: 

It is very easy in WPF - so yes, it is possible in .NET Framework. (you have controls in WPF that can contain other controls like a panel that can have label checkbox and textbox, I am not sure if there is a timer control, but I'm sure it can be programmed).

In Winforms, it is harder, it might be easier using a grid and gridview rather than a listbox, but it there is some work to do.

There are commercial controls - than will make this features easier to achieve. (DevExpress Grid for winforms)

Dani
@DaniThank you for your reply.Actually i have a list of devices that is to be placed in the listbox, now this list can grow to any extend so i need a scroll bar. There is no scroll bar in panel,group box or other container controls.
Pradeep
There is a way to add a scroll bar to WPF. the scroll control should contain the panel if I recall right. Is WPF is an option ?
Dani
+1  A: 

As Dani says, it is very easy in WPF. To give you an idea of how simple it is, here is how you would do it using the Expression Blend designer tool or using code:

If you just drag a ListBox onto a WPF Window or UserControl, then in the Properties window at the ItemTemplate property select "New Template", you will get a ListBox with a custom template. Create a panel (such as DockPanel) inside your template and drag Labels, CheckBoxes, TextBoxes and other controls into it.

By following this procedure, the designer will create XAML similar to the following:

<ListBox ItemsSource="{Binding myItems}">

  <ListBox.ItemTemplate>
    <DataTemplate TargetType="{x:Type MyItemType}">

      <DockPanel>

        <Label Content="Hello:"/>
        <CheckBox Content="Click Here" />
        <TextBox Text="Here is my text" />

      </DockPanel>

    </DataTemplate>

  </ListBox.ItemTemplate>
</ListBox>

Alternatively you can just write the XAML yourself. It's amazing how easy it is to do so with IntelliSense.

Ray Burns
+1  A: 

if WPF is not an option you could use a DataGridView control with: DataGridViewCheckBoxColumn for your checkbox and 2 DataGridViewTextBoxColumn's for Label and TextBox. You can set grid's property SelectionMode to FullRowSelect to select the entire row. Also check grid's CellPainting event; you can add some custom painting code there.

serge_gubenko