我正在使用 ItemCheckEventArgs 并且可以从中获取索引值,但是从该值中我不确定如何查找所检查的文本是什么。
问问题
17014 次
4 回答
5
这是一些应该可以解决问题的基本代码:
public void CheckedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
var checkedListBox = (CheckedListBox)sender;
var checkedItemText = checkedListBox.Items[e.Index].ToString();
}
于 2010-11-17T15:52:56.110 回答
3
在使用 ItemCheckEventArgs e 的 ItemCheck 事件处理程序中,您可以检索相应的对象
checkedListBox1.Items[e.Index]
于 2010-11-17T15:55:07.870 回答
1
该类CheckedListBox
有一个CheckedItems
属性。
private void WhatIsChecked_Click(object sender, System.EventArgs e) {
// Display in a message box all the items that are checked.
// First show the index and check state of all selected items.
foreach(int indexChecked in checkedListBox1.CheckedIndices) {
// The indexChecked variable contains the index of the item.
MessageBox.Show("Index#: " + indexChecked.ToString() + ", is checked. Checked state is:" + checkedListBox1.GetItemCheckState(indexChecked).ToString() + ".");
}
// Next show the object title and check state for each item selected.
foreach(object itemChecked in checkedListBox1.CheckedItems) {
// Use the IndexOf method to get the index of an item.
MessageBox.Show("Item with title: \"" + itemChecked.ToString() +
"\", is checked. Checked state is: " + checkedListBox1.GetItemCheckState(checkedListBox1.Items.IndexOf(itemChecked)).ToString() + ".");
}
}
于 2010-11-17T15:55:34.127 回答
0
在SelectedIndexChanged
事件内部,输入以下代码
string text = (sender as CheckedListBox).SelectedItem.ToString();
于 2010-11-17T15:53:05.973 回答