我有list_box的处理程序:
private void list_answers_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < tasks.Count; i++)
{
if (list_answers.Text == "Question №" + (i + 1))
{
this.ShowOnePanel(i);
iter = i;
break;
}
}
}
和list_view:
private void list_answers_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < tasks.Count; i++)
{
if (list_answers.Items[i].Text == "Question №" + (i + 1))
{
this.ShowOnePanel(i);
iter = i;
break;
}
}
}
适用于列表框,但不适用于listview。为什么?
附: ShowOnePanel
是我的方法,它显示了一个有疑问的小组。
答案 0 :(得分:0)
if (list_answers.Items[i].Text == "Питання №" + (i + 1))
我猜它"question"
不是"Питання"
修改强>
private void list_answers_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < tasks.Count; i++)
{
if (list_answers.Items[i].Selected == true) // find selected item
{
if (list_answers.Items[i].Text == "Question №" + (i + 1)) // check it's content
this.ShowOnePanel(i);
iter = i;
break;
}
}
}