本文介绍了如何在复选框列表中获取当前的选中项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表框,我试图在ItemCheck Handler中获取当前选中的项目,但是我不能,
->我可以使用属性chckdLstBox_Metabolites.CheckedItems
获取CheckedItems列表。我会得到刚刚检查过的项目吗??
I have a list box and i am trying to get currently checked item inside ItemCheck Handler , but i couldn't ,->I can get List of CheckedItems using property chckdLstBox_Metabolites.CheckedItems But how do i get the item that is checked just before????
推荐答案
您可以使用事件的ItemCheckEventArgs:
You can use the event's ItemCheckEventArgs:
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
//Note: MessageBox is for demo use only
MessageBox.Show("Selected Index: " + e.Index.ToString());
MessageBox.Show("Current Value: " + e.CurrentValue.ToString());
MessageBox.Show("New Value: " + e.NewValue.ToString());
//Getting the item would be:
string currentItem = (string)this.checkedListBox1.Items[e.Index];
MessageBox.Show("Current Item: " + currentItem);
}
这篇关于如何在复选框列表中获取当前的选中项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!