最近的项目中用到了checkedListBox这个控件,并且需要获得选中项的文本。
直接贴代码:
private void button2_Click(object sender, EventArgs e)
{
string checkedText = string.Empty;
for (int i = 0; i < this.myCheckedlistBox.CheckedItems.Count; i++)
{
checkedText += (String.IsNullOrEmpty(checkedText) ? "" : ",") + this.myCheckedlistBox.GetItemText(this.myCheckedlistBox.CheckedItems[i]);
}
this.DisplayText.Text = checkedText;
}
通过点击button2,将checkedListBox中选中项的文本显示到textbox即DisplayText中。