listView问题 [英] listView question

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

问题描述



使用这个程序我可以做一个选择,

但是第二次我得到一个错误

///// ////////////表示。请帮助。


使用System;

使用System.Drawing;

使用System.Collections;

使用System.ComponentModel;

使用System.Windows.Forms;

使用System.Data;

命名空间WindowsApplication1

{

公共类Form1:System.Windows.Forms.Form

{

private System.Windows.Forms.TextBox textBox1;

private System.Windows.Forms.ColumnHeader columnHeader1;

private System.Windows.Forms.ColumnHeader columnHeader2;

private System.Windows.Forms .ListView listView1;

private System.ComponentModel.Container components = null;

public Form1()

{

InitializeComponent();

}

protected override void Dispose(bool disposing)

{

if(disposing) )

{

if(components!= null)

{

components.Dispose();

}

}

base.Disp ose(处理);

}

#region Windows窗体设计器生成的代码

private void InitializeComponent()

{

this.textBox1 = new System.Windows.Forms.TextBox();

this.columnHeader1 = new System.Windows.Forms.ColumnHeader();

this.columnHeader2 = new System.Windows.Forms.ColumnHeader();

this.listView1 = new System.Windows.Forms.ListView();

this.SuspendLayout();

//

// textBox1

//

this.textBox1。 Location = new System.Drawing.Point(16,192);

this.textBox1.Name =" textBox1";

this.textBox1.Size = new System。 Drawing.Size(256,20);

this.textBox1.TabIndex = 1;

this.textBox1.Text ="";

//

// columnHeader1

//

this.columnHeader1.Text =" number";

this.columnHeader1.Width = 49;

//

// columnHeader2

//

this.columnHeader2.Text =" name";

this.columnHeader2.Width = 186;

//

// listView1

//

this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader [] {

this.columnHeader1,

this.columnHeader2});

this.listView1.GridLines = true;

this.listView1.LabelEdit = true;

this.listView1.Location = new System.Drawing.Point(24,16);

this.listView1.Name =" listView1";

this.listView1 .Size = new System.Drawing.Size(256,160);

this.listView1.TabIndex = 0;

this.listView1.View = System.Windows.Forms .View.Details;

this.listView1.SelectedIndexChanged + = new

System.EventHandler(this.listView1_SelectedIndexCh anged);

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5,13);

this.ClientSize = new System.Drawing.Size(292,266);

thi s.Controls.Add(this.textBox1);

this.Controls.Add(this.listView1);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle。 FixedToolWind ow;

this.Name =" Form1";

this.ShowInTaskbar = false;

this.Text =" Form1" ;

this.Load + = new System.EventHandler(this.Form1_Load);

this.ResumeLayout(false);

}

#endregion

[STAThread]

static void Main()

{

申请表.Run(new Form1());

}

private void listView1_SelectedIndexChanged(object sender,EventArgs e)

{

ListView.SelectedListViewItemCollection contents =

this.listView1.SelectedItems;

textBox1.Text = contents [0] .SubItems [1] .Text; //// /////////////////错误

}

private void Form1_Load(object sender,System.EventArgs e)

{

string [] show0 = new string [] {" one,two&quo t;,三,四};

string [] show1 = new string [] {" ene"," mene"," mane"," moo" ;};

for(int i = 0; i< show0.Length; i ++)

{

ListViewItem listItem = new ListViewItem(show0 [i]);

using System;

使用System.Drawing;

使用System.Collections;

使用System.ComponentModel;

使用System.Windows。表单;

使用System.Data;

命名空间WindowsApplication1

{

公共类Form1:System.Windows。 Forms.Form

{

private System.Windows.Forms.TextBox textBox1;

private System.Windows.Forms.ColumnHeader columnHeader1;

private System.Windows.Forms.ColumnHeader columnHeader2;

private System.Windows.Forms.ListView listView1;

private System.ComponentModel.Container components = null;

public Form1()

{

InitializeComponent();

}

protected override void Dispose(bool disposing)

{

if(disposing)

{

if( components!= null)

{

components.Dispose();

}

}

base.Dispose(disposing);

}

#region Windows窗体设计器生成的代码

private void InitializeComponent()

{

this.textBox1 = new System.Windows.Forms.TextBox();

this.columnHeader1 = new System.Windows.Forms.ColumnHeader();

this.columnHeader2 = new System.Windows.Forms.ColumnHeader();

this.listView1 = new System.Windows.Forms.ListView();

this.SuspendLayout();

//

// textBox1

//

this.textBox1.Location = new System.Drawing.Point( 16,192);

this.textBox1.Name =" textBox1";

this.textBox1.Size = new System.Drawing.Size(256,20);

this.textBox1.TabIndex = 1;

this.textBox1.Text ="" ;;

//

// columnHeader1

//

this.columnHeader1.Text =" number";

this.columnHeader 1.Width = 49;

//

// columnHeader2

//

this.columnHeader2.Text =" name";

this.columnHeader2.Width = 186;

//

// listView1

//

this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader [] {

this.columnHeader1,

this.columnHeader2});

this.listView1.GridLines = true;

this.listView1.LabelEdit = true;

this.listView1。 Location = new System.Drawing.Point(24,16);

this.listView1.Name =" listView1";

this.listView1.Size = new System。 Drawing.Size(256,160);

this.listView1.TabIndex = 0;

this.listView1.View = System.Windows.Forms.View.Details;

this.listView1.SelectedIndexChanged + = new

System.EventHandler(this.listView1_SelectedIndexCh anged);

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5,13);

this.ClientSize = new System.Drawing.Size(292,266);

this.Controls.Add(this.textBox1);

this.Controls.Add(this.listView1);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWind ow;

this.Name =" Form1" ;;

this.ShowInTaskbar = false;

this.Text =" Form1";

this.Load + = new System.EventHandler (this.Form1_Load);

this.ResumeLayout(false);

}

#endregion

[STAThread ]

static void Main()

{

Application.Run(new Form1());

}

private void listView1_SelectedIndexChanged(object sender,EventArgs e)

{

ListView.SelectedListViewItemCollection contents =

this。 listView1.SelectedItems;

textBox1.Text = contents [0] .SubItems [1] .Text; ///////////////////// error

}

private void Form1_Load(object sender,System.EventArgs e)

{

string [] show0 = new string [] {" one,two,three,four};

string [] show1 = new string [] {" ene",mene,mane,moo};

for(int i = 0; i< show0.Length; i ++)

{

ListViewItem listItem = new ListViewItem(show0 [i]);

listItem.SubItems.Add (show1 [i]);

listView1.Items.Add(listItem);

}

}

}

}

listItem.SubItems.Add(show1 [i]);

listView1.Items.Add(listItem);

}

}

}

}



With this program I can do one selection,
but upon the second I get an error where
///////////////// is indicated. Please help.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ListView listView1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.listView1 = new System.Windows.Forms.ListView();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 192);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(256, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// columnHeader1
//
this.columnHeader1.Text = "number";
this.columnHeader1.Width = 49;
//
// columnHeader2
//
this.columnHeader2.Text = "name";
this.columnHeader2.Width = 186;
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2});
this.listView1.GridLines = true;
this.listView1.LabelEdit = true;
this.listView1.Location = new System.Drawing.Point(24, 16);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(256, 160);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.SelectedIndexChanged += new
System.EventHandler(this.listView1_SelectedIndexCh anged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.listView1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWind ow;
this.Name = "Form1";
this.ShowInTaskbar = false;
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
ListView.SelectedListViewItemCollection contents =
this.listView1.SelectedItems;
textBox1.Text = contents[0].SubItems[1].Text;/////////////////////error
}
private void Form1_Load(object sender, System.EventArgs e)
{
string [ ] show0 = new string [] {"one","two","three","four"};
string [ ] show1 = new string [] {"ene","mene","mane","moo"};
for (int i = 0; i<show0.Length;i++)
{
ListViewItem listItem = new ListViewItem(show0[i]);
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ListView listView1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.listView1 = new System.Windows.Forms.ListView();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 192);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(256, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// columnHeader1
//
this.columnHeader1.Text = "number";
this.columnHeader1.Width = 49;
//
// columnHeader2
//
this.columnHeader2.Text = "name";
this.columnHeader2.Width = 186;
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2});
this.listView1.GridLines = true;
this.listView1.LabelEdit = true;
this.listView1.Location = new System.Drawing.Point(24, 16);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(256, 160);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.SelectedIndexChanged += new
System.EventHandler(this.listView1_SelectedIndexCh anged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.listView1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWind ow;
this.Name = "Form1";
this.ShowInTaskbar = false;
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
ListView.SelectedListViewItemCollection contents =
this.listView1.SelectedItems;
textBox1.Text = contents[0].SubItems[1].Text;/////////////////////error
}
private void Form1_Load(object sender, System.EventArgs e)
{
string [ ] show0 = new string [] {"one","two","three","four"};
string [ ] show1 = new string [] {"ene","mene","mane","moo"};
for (int i = 0; i<show0.Length;i++)
{
ListViewItem listItem = new ListViewItem(show0[i]);
listItem.SubItems.Add(show1[i]);
listView1.Items.Add(listItem);
}
}
}
}
listItem.SubItems.Add(show1[i]);
listView1.Items.Add(listItem);
}
}
}
}


推荐答案

错误是因为一个事件在SelectedItems中没有任何内容被触发......

因此尝试访问内容[0]失败,因为没有任何内容内容。


有点奇怪的是,有一个事件没有选中的项目被激活 - 它好像

似乎,当你点击第二个不同的项目时(没有shift键 -

即没有进行多项选择),在列表框选择内部已清除
,导致事件被包含任何内容的SelectedItems触发,
在添加第二项之前
selectedItems和事件被解雇

再次。


你应该总是防止没有选择,

特别是一个多选列表框 - 即这样的东西:


if(contents.Count> 0)

textBox1.Text = contents [0] .SubItems [1] .Text;

else

textBox1.Text ="(没什么);

干杯,

Pete Beech

" Vanessa" < VA ***** @ hipperdy.hop>在留言中写道

news:10 *************** @ news-01.evisp.enertel.nl ...
The error is because an event is firing with nothing in the SelectedItems...
so trying to access contents[0] fails because there is nothing in contents.

Its a bit strange that there is an event fired with no selected items - it
seems that, when you click on a 2nd different item (without the shift key -
i.e. not making a multi selection), internally the listbox selection is
cleared, causing the event to fire with SelectedItems containing nothing,
before the 2nd item is added to the SelectedItems and the event is fired
again.

You should always protect against there being no selection anyway,
especially in a multiselect listbox - i.e. something like this:

if (contents.Count > 0)
textBox1.Text = contents[0].SubItems[1].Text;
else
textBox1.Text = "(Nothing)";
Cheers,
Pete Beech
"Vanessa" <va*****@hipperdy.hop> wrote in message
news:10***************@news-01.evisp.enertel.nl...

有了这个程序,我可以做一个选择,但是第二次我收到一个错误,表示
/////////////////。请帮助。

使用System;
使用System.Drawing;
使用System.Collections;
使用System.ComponentModel;
使用System.Windows。表单;
使用System.Data;
命名空间WindowsApplication1
{公共类Form1:System.Windows.Forms.Form
{
私有System.Windows .Forms.TextBox textBox1;
私有System.Windows.Forms.ColumnHeader columnHeader1;
私有System.Windows.Forms.ColumnHeader columnHeader2;
私有System.Windows.Forms.ListView listView1;
private System.ComponentModel.Container components = null;
public Form1()
{InitialifyComponent();
}
protected override void Dispose(bool disposing)
{
if(disposing)
{
if(components!= null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows窗体设计器生成的代码
private void InitializeComponent()
{
这个.textBox1 = new System.Windows.Forms.TextBox();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.listView1 = new System.Windows.Forms.ListView();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16,192);
this.textBox1.Name =" textBox1";
this.textBox1.Size = new System.Drawing。大小(256,20);
this.textBox1.TabIndex = 1;
this.textBox1.Text ="" ;;
//
// columnHeader1
//
this.columnHeader1.Text =" number";
this.columnHeader1.Width = 49;
//
// columnHeader2
//
this.columnHeader2.Text =" name";
this.columnHeader2.Width = 186;
//
// listView1
//
这个.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader [] {
this.columnHeader1,
this.columnHeader2});
this.listView1。 GridLines = true;
this.listView1.LabelEdit = true;
this.listView1.Location = new System.Drawing.Point(24,16);
this.listView1.Name =" listView1" ;;
this.listView1.Size = new System.Drawing.Size(256,160);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows .Forms.View.Details;
this.listView1.SelectedIndexChanged + = new
System.EventHandler(this.listView1_SelectedIndexCh anged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5,13);
this.ClientSize = new System.Drawing.Size(292,266);
this.Controls。添加(this.textBox1);
this.Controls.Add(this.listView1);
this.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.FixedToolWind ow; this.Name =" Form1";
this.ShowInTaskbar = false;
this.Text =" Form1";
this.Load + = new System.EventHandler(this.Form1_Load) ;
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
应用程序。运行(new Form1());
}
private void listView1_SelectedIndexChanged(object sender,EventArgs e)
{ListView.SelectedListViewItemCollection contents =
this.listView1.SelectedItems ;
textBox1.Text = contents [0] .SubItems [1] .Text; /////////////////////错误
}
private void Form1_Load(object sender,System.EventArgs e)
{
string [] show0 = new string [] {" one",two,three,"四个"};
string [] show1 = new string [] {" ene",mene,mane,moo};
for(int i = 0; i< show0.Length; i ++)
{ListViewItem listItem = new ListViewItem(show0 [i]);
listItem.SubI tems.Add(show1 [i]);
listView1.Items.Add(listItem);
}
}
}
}

With this program I can do one selection,
but upon the second I get an error where
///////////////// is indicated. Please help.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ListView listView1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.listView1 = new System.Windows.Forms.ListView();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 192);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(256, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// columnHeader1
//
this.columnHeader1.Text = "number";
this.columnHeader1.Width = 49;
//
// columnHeader2
//
this.columnHeader2.Text = "name";
this.columnHeader2.Width = 186;
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2});
this.listView1.GridLines = true;
this.listView1.LabelEdit = true;
this.listView1.Location = new System.Drawing.Point(24, 16);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(256, 160);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.SelectedIndexChanged += new
System.EventHandler(this.listView1_SelectedIndexCh anged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.listView1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWind ow; this.Name = "Form1";
this.ShowInTaskbar = false;
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
ListView.SelectedListViewItemCollection contents =
this.listView1.SelectedItems;
textBox1.Text = contents[0].SubItems[1].Text;/////////////////////error
}
private void Form1_Load(object sender, System.EventArgs e)
{
string [ ] show0 = new string [] {"one","two","three","four"};
string [ ] show1 = new string [] {"ene","mene","mane","moo"};
for (int i = 0; i<show0.Length;i++)
{
ListViewItem listItem = new ListViewItem(show0[i]);
listItem.SubItems.Add(show1[i]);
listView1.Items.Add(listItem);
}
}
}
}


谢谢Pete,


你的建议解决了这个问题。


你能输入吗?进入listView?我没有看到Read Only = true / false

with the Properties。

" Pete Beech" < PE ********* @ hotmail.nojunk.com>在消息中写道

news:un ************* @ TK2MSFTNGP12.phx.gbl ...
Thank you Pete,

Your suggestion solved that one.

Can you also input into a listView? I do not see a "Read Only = true/false"
in with the Properties.
"Pete Beech" <pe*********@hotmail.nojunk.com> wrote in message
news:un*************@TK2MSFTNGP12.phx.gbl...
你应该始终保护那里无论如何都没有选择,特别是在多选列表框中 - 例如:

if(contents.Count> 0)
textBox1.Text = contents [0]。 SubItems [1] .Text;
else
textBox1.Text ="(Nothing)" ;;
You should always protect against there being no selection anyway,
especially in a multiselect listbox - i.e. something like this:

if (contents.Count > 0)
textBox1.Text = contents[0].SubItems[1].Text;
else
textBox1.Text = "(Nothing)";



将LabelEdit设置为true允许编辑第一列(''label'')

。 (在示例中,LabelEdit设置为true。)要编辑,您可以单击

单击已选中的项目。


" Patrick de里德" < SE *** @ freeler.nl>在留言中写道

news:10 *************** @ news-01.evisp.enertel.nl ...
Setting LabelEdit to true allows the first column (the ''label'') to be
edited. (In the example, LabelEdit is set to true.) To edit, you can single
click an item that is already selected.

"Patrick de Ridder" <se***@freeler.nl> wrote in message
news:10***************@news-01.evisp.enertel.nl...
谢谢Pete,

你的建议解决了那个问题。

你还可以输入listView吗?我没有看到Read Only =
true / false与属性。

Pete Beech < PE ********* @ hotmail.nojunk.com>在消息中写道
新闻:un ************* @ TK2MSFTNGP12.phx.gbl ...
Thank you Pete,

Your suggestion solved that one.

Can you also input into a listView? I do not see a "Read Only = true/false" in with the Properties.
"Pete Beech" <pe*********@hotmail.nojunk.com> wrote in message
news:un*************@TK2MSFTNGP12.phx.gbl...
你应该总是防止没有选择,特别是在多选列表框中 - 例如:

if(contents.Count> 0)
textBox1.Text = contents [0] .SubItems [1] .Text;
其他
textBox1.Text ="(Nothing)" ;;
You should always protect against there being no selection anyway,
especially in a multiselect listbox - i.e. something like this:

if (contents.Count > 0)
textBox1.Text = contents[0].SubItems[1].Text;
else
textBox1.Text = "(Nothing)";




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

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