list_view_SelectedIndexChanged和list_box_SelectedIndexChanged之间的类比

时间:2014-04-14 00:29:52

标签: c# winforms listview

我有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是我的方法,它显示了一个有疑问的小组。

1 个答案:

答案 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;
                }
            }
    }