如何将CheckedListBox选中的项目放入列表......? [英] How to get the CheckedListBox Selected Items into List…?
本文介绍了如何将CheckedListBox选中的项目放入列表......?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我有一个X类型的列表.X是一个属性级别类。
现在在一个事件上我需要将CheckedListBox所选项目放入另一个列表< ; X> ;.
如何获得输出...... ??
我试过的代码如下...
Hello,
I am having a List of type X. X is a Property Level Class.
Now on an event i need the CheckedListBox Selected Items into another List<X>.
How to get the output...??
The code i tried is given below...
public void Initialize(List<X> x1)
{
chkList.DataSource = x1;
chkList.DisplayMember = "MeterName"; // MeterName is a property in Class X
chkList.ValueMember = "PortNum"; // PortNum is a property in Class X
}
private void Click_Event(object sender, EventArgs e)
{
List<X> x2 = new List<X>();
// Here I want to get the checkedListBox selected items in x2;
// How to get it...???
}
推荐答案
private void Click_Event(object sender, EventArgs e)
{
var x2 = new List<X>();
foreach (X item in chkList.CheckedItems)
{
x2.Add(item);
}
}
试试这个
Hi, try this
List<x> x2 = new List<x>();
foreach (ListItem Ck in chkbl.Items)
{
if (Ck.Selected == true)
{
x2.add(Ck.Text.ToString().Trim());
}
}
这篇关于如何将CheckedListBox选中的项目放入列表......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文