Say that I have a CheckedListBox with items \"1\", \"2\", \"3\", \"4\", and \"5\" in that order and I want to select \"2\", \"3\", and \"4\" by selecting \"2\" then holding
Multiple selection is not supported, but i got here by search to find the CheckedItems.
The selected items refers to the items that are marked, the checked items refers to the items that are checked.
Hence use .CheckedItems property instead of .SelectedItems if you want the items with a checked checkbox.
There might be an easier alternative, but you could use a ListView
, set CheckBoxes
to true
, HeaderStyle
to None
, and View
to List
.
Correction:
Should have been set View
to Details
.
It appears that it it not possible to set see the remarks section in CheckedListBox.SelectionMode Property
For an easier alternative follow the adivice of adrift.
for the multichecks i came up with this today:
List<int> listBox2_selectionhistory = new List<int>();
private void checkedListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
int actualcount = listBox2_selectionhistory.Count;
if (actualcount == 1)
{
if (Control.ModifierKeys == Keys.Shift)
{
int lastindex = listBox2_selectionhistory[0];
int currentindex = checkedListBox2.SelectedIndex;
int upper = Math.Max(lastindex, currentindex) ;
int lower = Math.Min(lastindex, currentindex);
for (int i = lower; i < upper; i++)
{
checkedListBox2.SetItemCheckState(i, CheckState.Checked);
}
}
listBox2_selectionhistory.Clear();
listBox2_selectionhistory.Add(checkedListBox2.SelectedIndex);
}
else
{
listBox2_selectionhistory.Clear();
listBox2_selectionhistory.Add(checkedListBox2.SelectedIndex);
}
}
as far as i know checkedlistboxes' SelectionMode can only be either one or none which means you can never make the app select more than 1 at a time (I also used this behavior to simplify my code for checkedlistboxes)
private System.Windows.Forms.CheckedListBox LBO1;
string mySentLst = string.Join(";", LBO1.CheckedItems.Cast<string>());
Please follow these steps:
Select CheckOnClick
= true.
When you want to retrieve selected item, use GetItemChecked(int index)
method instead.