ListView的错误C# [英] listview error c#

查看:107
本文介绍了ListView的错误C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListView。我想从它的第一个元素,然后调用一个方法。问题是,虽然我已经在我不知道为什么下面的代码不工作时,我要选择的元素列表视图的元素。需要帮助。 THX

  listview.Items [0] .Selected = TRUE; 
listview.Select();
INT C = listview.SelectedItems.Count;
MessageBox.Show(C +:与:+ listview.Items [0]的ToString()); .//here的C = 0,它应该是1 :(
// Thread.sleep代码(3000);
法();

我有:

  ListViewItem的IT =新的ListViewItem(一); 
it.SubItems.Add(S);
it.SubItems.Add(v);
it.Tag =调用;
列表视图。 Items.Add(它);


解决方案

  System.Windows.Forms.ListViewItem listViewItem4 =新System.Windows.Forms.ListViewItem(fdasf); 
系统。 Windows.Forms.ListViewItem listViewItem5 =新System.Windows.Forms.ListViewItem(sdfsadf);
System.Windows.Forms.ListViewItem listViewItem6 =新System.Windows.Forms.ListViewItem(gdsgdfg);

  this.listView1.Items.AddRange(新System.Windows.Forms.ListViewItem [] {
listViewItem4,
listViewItem5,
listViewItem6});
this.listView1.Location =新System.Drawing.Point(84,88);
this.listView1.Name =ListView1的;
this.listView1.Size =新System.Drawing.Size(121,97);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = FALSE;
this.listView1.View = System.Windows.Forms.Vi​​ew.List;



这个工程,c为1

  listView1.Items [0] .Selected = TRUE; 
listView1.Select();
INT C = listView1.SelectedItems.Count;
MessageBox.Show(C +:与:+ listView1.Items [0]的ToString());
// Thread.sleep代码(3000);
法();



在这里输入的形象描述



这个问题可能是在其他地方。


I have a ListView. I want to select the first element from it and then invoke a method. The thing is that though i have the element in the listview I dont know why the following code is not working when i want to select the element. need help. 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();  

I have:

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

解决方案

for

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");

and

this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
    listViewItem4,
    listViewItem5,
    listViewItem6});
this.listView1.Location = new System.Drawing.Point(84, 88);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(121, 97);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.List;

this works and c is 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();  

The problem is probably somewhere else.

这篇关于ListView的错误C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆