最近的项目中用到了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中。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231976.html原文链接:https://javaforall.net
