c# checklistbox 如何取选择的值?例如:我选择了第1、3、5的选项,如何获取它的值?

如题所述

第1个回答  2012-10-23
首先用for或foreach进行遍历,然后用if判断该选项是否被选中,如果选中,则去该值。 比如checkBox.Value
第2个回答  推荐于2018-05-10
/// <summary>
/// C#中获取CheckListBox选中项的值。
/// </summary>
/// <param name="clb">要被获取选中项的CheckListBox类型的对象。</param>
/// <returns>返回一个ArrayList类型的对象。</returns>
private ArrayList GetCheckedItemsText(CheckedListBox clb)
{
ArrayList result = new ArrayList();
IEnumerator myEnumerator = clb.CheckedIndices.GetEnumerator();
int index;
while (myEnumerator.MoveNext())
{
index = (int)myEnumerator.Current;
clb.SelectedItem = clb.Items[index];
result.Add(clb.Text);
}
return result; }

或者 你可以使用遍历

for (int i = 0; i < checkedListBox1.Items.Count; i++)

{

if (checkedListBox1.GetItemChecked(i))

{

MessageBox.Show(checkedListBox1.GetItemText(checkedListBox1.Items[i])); //弹出选中值

}

}本回答被网友采纳
相似回答