Adding controls to items in a listbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to have a listbox that shows a checkbox and a textbox.

I created a user control that has a checkbox and a textbox in it and have
been trying to add it to a listbox but I can't get it to show up for each
item I add to the listbox.

foreach (Column column in columns)
{
ColumnsListBox.Items.Add(column.Name);
ColumnsListBox.Controls.Add(new ColumnListControl(true, column.Name,
column.Name));
}

I've also looked at using an Owner Draw listbox but can't figure that out
either.

I basically need something that looks like a listbox with 2 columns in it --
a checkbox and a textbox.

How can I get that to work so I can add items to the object and set the
subitem values?

Thanks in advance.
 
First I should say I'm doing this in a Windows Form.

I would prefer a listbox but I don't care if it's a listview in detailview
or not.

I basically want something like a listbox that has a list containing a
checkbox and a textbox that scrolls.

So the list would look like this:

checkbox textbox
checkbox textbox
checkbox textbox

I tried creating a user control that has a checkbox and textbox and putting
that onto a listbox but I wasn't able to get that to work.

The closest I've come is using a ListView. Except the problem is that the
controls don't scroll. If I could get the scrolling to work then I'd have it.

Here's what I've got so far:

foreach (Column column in columns)
{
ListViewItem item = new ListViewItem();
item.Text = column.Name;
listView1.Items.Add(item);

ColumnListControl control = new ColumnListControl(true, column.Name,
column.Name);
control.Height = item.Bounds.Height;
control.Location = new Point(0, item.Bounds.Y);
listView1.Controls.Add(control);
}


-------------------------
 
Back
Top