CheckedListBox

  • Thread starter Thread starter MSDN Newsgroups
  • Start date Start date
M

MSDN Newsgroups

Hi...
Does anybody know how can i access the value of the checked items on a
CheckedListBox ?
I´m populating the CLB using the DataSource property passing a DataTable.

Thanks in advance!!
 
Here is the MSDN help for CheckListBox:

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfsystemwindowsformscheckedlistboxclassto
pic.asp

You can access the checked items via the "CheckedItems"
property. That property returns a
CheckedItemCollection. The CheckedItemCollection's
documentation can be found at:

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfsystemwindowsformscheckedlistboxchecked
itemcollectionclasstopic.asp

Here is an excerpt from the CheckedItemCollection's
documentation showing how to access the items in the
collection:

// Next show the object title and check state for
each item selected.
foreach(object itemChecked in
checkedListBox1.CheckedItems) {

// Use the IndexOf method to get the index of an
item.
MessageBox.Show("Item with title: \"" +
itemChecked.ToString() +
"\", is checked. Checked state
is: " +
checkedListBox1.GetItemCheckState
(checkedListBox1.Items.IndexOf(itemChecked)).ToString()
+ ".");
}


-- Jake
(e-mail address removed)
 
The problem is that when I try to access the value property it returns a
reference to the DataTable from which it was populated and not the actual
value!!!



Here is the MSDN help for CheckListBox:

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfsystemwindowsformscheckedlistboxclassto
pic.asp

You can access the checked items via the "CheckedItems"
property. That property returns a
CheckedItemCollection. The CheckedItemCollection's
documentation can be found at:

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfsystemwindowsformscheckedlistboxchecked
itemcollectionclasstopic.asp

Here is an excerpt from the CheckedItemCollection's
documentation showing how to access the items in the
collection:

// Next show the object title and check state for
each item selected.
foreach(object itemChecked in
checkedListBox1.CheckedItems) {

// Use the IndexOf method to get the index of an
item.
MessageBox.Show("Item with title: \"" +
itemChecked.ToString() +
"\", is checked. Checked state
is: " +
checkedListBox1.GetItemCheckState
(checkedListBox1.Items.IndexOf(itemChecked)).ToString()
+ ".");
}


-- Jake
(e-mail address removed)
 
Back
Top