C# listview错误c

C# listview错误c,c#,C#,我有一个列表视图。我想从中选择第一个元素,然后调用一个方法。问题是,虽然我在listview中有这个元素,但我不知道当我想要选择这个元素时,为什么下面的代码不起作用。我需要帮助。thx listview.Items[0].Selected = true; listview.Select(); int c =listview.SelectedItems.Count; MessageBox.Show(c + ": and : " + listview.Items[0].ToString()); ./

我有一个列表视图。我想从中选择第一个元素,然后调用一个方法。问题是,虽然我在listview中有这个元素,但我不知道当我想要选择这个元素时,为什么下面的代码不起作用。我需要帮助。thx

listview.Items[0].Selected = true;
listview.Select();
int c =listview.SelectedItems.Count;
MessageBox.Show(c + ": and : " + listview.Items[0].ToString()); .//here the c=0 and it should be 1:(
//  Thread.Sleep(3000);
method();  
我有:

ListViewItem it = new ListViewItem("a");
it.SubItems.Add("s");
it.SubItems.Add(""v");
it.Tag = call;
listview.Items.Add(it);

listview.SelectedIndex=1; 试试这个。

看看

System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem("fdasf");
System.Windows.Forms.ListViewItem listViewItem5 = new System.Windows.Forms.ListViewItem("sdfsadf");
System.Windows.Forms.ListViewItem listViewItem6 = new System.Windows.Forms.ListViewItem("gdsgdfg");

这是可行的,c是1

listView1.Items[0].Selected = true;
listView1.Select();
int c =listView1.SelectedItems.Count;
MessageBox.Show(c + ": and : " + listView1.Items[0].ToString());
//  Thread.Sleep(3000);
method();  

问题可能在其他地方。

您似乎在使用正确的方式选择项目:

listview.Items[0].Selected = true;

我没有选择索引..只选择了项listviewitem4是我的子项
listview.Items[0].Selected = true;