如何使用 C# 在选中的列表框中获取新选中项的文本

Jus*_*ten 2 c# checkedlistbox

我正在使用 ItemCheckEventArgs 并且可以从中获取索引值,但是从该值中我不确定如何查找所检查的文本的内容。

Jus*_*ner 5

这是一些应该可以解决问题的基本代码:

public void CheckedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
    var checkedListBox = (CheckedListBox)sender;
    var checkedItemText = checkedListBox.Items[e.Index].ToString();
}
Run Code Online (Sandbox Code Playgroud)


Nic*_*eon 5

在 ItemCheck 事件处理程序中使用 ItemCheckEventArgs e 您可以检索相应的对象

checkedListBox1.Items[e.Index]
Run Code Online (Sandbox Code Playgroud)