【发布时间】:2011-05-31 22:03:08
【问题描述】:
我在列表框内运行时生成了复选框,问题是我怎么知道选中的复选框是什么?
我在 C# 中尝试了以下代码:
CheckBox box;
if ( box.Checked )
if ( box.IsChecked )
这是以下代码:
public partial class Choose_Users
{
Service1Client C = new Service1Client();
Array a;
user_detail d;
String F_Name, L_Name;
CheckBox user = new CheckBox();
public Choose_Users()
{
InitializeComponent();
a = C.GetData();
for (int i = 0; i < a.Length; i++)
{
d = (user_detail)a.GetValue(i);
user.Name = d.First_name;
user.Content= d.First_name;
listBox1.Items.Add(user);
}
}
private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
List<user_detail> list = new List<user_detail>();
foreach(CheckBox box in this.listBox1.Items)
{
if (box.Checked // here my problem is
{
}
}
}
}
他们没有工作。有什么帮助吗?
【问题讨论】:
-
@Sofia,您发布了一个问题,几乎没有提供关于您使用什么语言、环境等进行检查的上下文。请使用相关详细信息编辑您的问题并更新标签以反映您试图获得答案的内容。
-
“它不起作用”没有回答问题。投票结束。
-
box.Checked 绝对不会做任何事情,因为它是事件。 box.IsChecked 将返回该框是否被选中。
-
Mr.coldandtired,我在条件(如果(box.IsChecked))下尝试过它给我的错误,它不能从“布尔?”到“布尔”。
-
你确定你有
listbox而不是checkedListbox吗?据我所知,标准列表框中没有复选框项目