Reputation: 1
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?
Upvotes: 0
Views: 439
Reputation: 20492
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.
Upvotes: 1
Reputation: 62929
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.
Upvotes: 1
Reputation: 15079
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)
Upvotes: 0