CheckedListBox

  • Thread starter Thread starter s
  • Start date Start date
S

s

Hi!
I have Dataset named "bledy", where first column is ID and second is NAME .
I set all things by:

BledyCheckedListBox.DataSource = bledy.Tables[0];
BledyCheckedListBox.DisplayMember = bledy.Tables[0].Columns[1].ToString();
BledyCheckedListBox.ValueMember = bledy.Tables[0].Columns[0].ToString();

It might look dirty, but it works
Now... How can i get values of selected items? [ that means i need ID, not
NAME ]

I've found how to get selectedvalue [ but it works only for actually
selected item ].

Thanks in advance
 
this sample code could help you
// Next show the object title and check state for each item selected.
foreach (object itemChecked in
checkedListBox1.CheckedItems)
{
if
(checkedListBox1.GetItemCheckState(checkedListBox1.Items.IndexOf(itemChecked))
== CheckState.Checked)
{
//item is checked
}
else
{
//item is NOT checked
}
}

hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com
 
Uzytkownik "Galcho said:
this sample code could help you
// Next show the object title and check state for each item selected.
foreach (object itemChecked in
checkedListBox1.CheckedItems)
{
if
(checkedListBox1.GetItemCheckState(checkedListBox1.Items.IndexOf(itemChecked))
== CheckState.Checked)
{
//item is checked
}
else
{
//item is NOT checked
}
}

hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com
Thanks Galin, but i did it in quite nastier (but still working;) ) code
below:


private void BledyCheckedListBox_SelectedIndexChanged(object sender,
EventArgs e)

{

if ((BledyCheckedListBox.SelectedIndex < 0) ||

(BledyCheckedListBox.SelectedIndex > BledyCheckedListBox.Items.Count - 1))

{

}

else if (BledyCheckedListBox.GetSelected(BledyCheckedListBox.SelectedIndex))

{

if (!checkedItems.Contains(BledyCheckedListBox.SelectedValue))

checkedItems.Add(BledyCheckedListBox.SelectedValue);

}

else

{

if (checkedItems.Contains(BledyCheckedListBox.SelectedValue))

checkedItems.Remove(BledyCheckedListBox.SelectedValue);

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top