views:

3451

answers:

2

Hi,

I would like to add a checkbox control to a listbox control.

The listbox has to contain A couple of tasks, and I have to check if a tasks has been opened before.

I have a code sample, but it adds the checkbox as an object, not as a control

while (reader.Read())   
{                    
   CheckBox c = new CheckBox().Enabled = false;
   c.Text = reader.GetString(0) + ". " + reader.GetString(1);

   try 
   { 
      if (int.Parse(reader.GetString(2)) > 1) c.Checked = true; 
   } 
   catch(Exception ex)    
   {

      MessageBox.Show(ex.Message);    
   }    
   listTasks.Items.Add(c);
}

Can someone help me out

Thnx, Ruben

+1  A: 

A list box only supports a collection of string ListItems.

Adding a checkbox to it in that manner will result in the checkbox.ToString() value appearing.

You might want to look at the "CheckedListBox" control though I'm not sure if that exists in the CompactFramework.

Eoin Campbell
+4  A: 

The Compact Framework doesn't support the CheckedListBox control. You could use a ListView with the CheckBoxes property set to true.

Phaedrus
Okay, thank you :) that did the trick!