如何显示多列并从lis中获取多项选择 [英] How to display multicolumns and get back multi selections form lis

查看:65
本文介绍了如何显示多列并从lis中获取多项选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在Windows 2000上使用VS 2003进行Windows应用程序。我有一个

列表框,我已绑定到数据集表, "源"它有3列。

我想显示其中2列,scode和sname,在列表框中为1列

(如果不可能,那么2列将没问题)。

列表框可以显示数据集中的2列信息吗?我怎么能这样做?


另外,我将listbox的属性设置为selectionmode为MultiExtend 。

这是否允许用户使用

控制键从列表框中选择多行?如果是这样,那我怎样才能从列表框中取回选项?


提前感谢您提供的任何帮助,

Alpha

解决方案

>我正在使用Windows 2000上的VS 2003进行Windows应用程序。我已经将

列表框绑定到数据集表,源和源。它有3
列。我想显示其中的两列,scode和sname,作为1
列(如果不可能,那么2列将没问题)在列表框中。
列表框能否显示来自数据集的2列信息,如何进行
呢?


您可以向DataTable中添加另一列来组合数据

将另外两列合二为一。


私有DataTable dataTable1;


....


dataTable1 = new DataTable(" MyTable");

dataTable1.Columns.Add(" Column1",typeof(string));

dataTable1.Columns.Add(" Column2",typeof(string));

dataTable1.Columns.Add(" Column3",typeof(string));

dataTable1.Columns.Add(" Column1Column2",typeof(string))。Expression =

" Column1 +'',''+ Column2";


for(int x = 0; x< 25; x ++)

{

dataTable1.Rows.Add(new object [] {" FirstName" + x.ToString()," LastName" +

x.ToString()," Nothing",null});

}


this.lis tBox1.DisplayMember =" Column1Column2";

this.listBox1.DataSource = dataTable1;

另外,我将listbox的属性设置为selectionmode为MultiExtend。
这是否允许用户使用
控制键从列表框中选择多行?如果是这样,那么如何从
列表框中取回选项?


是的。你可以使用类似下面代码的代码来获得所选的值。


if(this.listBox1.SelectedItems.Count> 0)

{

int count = this.listBox1.SelectedItems.Count;

for(int x = 0; x< count; x ++)

{

DataRowView rowView = this.listBox1.SelectedItems [x] as DataRowView;

if(rowView!= null)

{

MessageBox.Show(rowView.Row [" Column1"]。ToString());

}

}

}


-

Tim Wilson

..Net Compact Framework MVP


" ;阿尔法" <铝*** @ discussions.microsoft.com>在消息中写道

新闻:AF ********************************** @ microsof t.com ...
我正在使用Windows 2000上的VS 2003进行Windows应用程序。我有
a列表框,我已绑定到数据集表,source它有3
列。我想显示其中的两列,scode和sname,作为1
列(如果不可能,那么2列将没问题)在列表框中。
列表框可以显示数据集中的2列信息吗?我该怎么做
呢?
另外,我将listbox的属性设置为选择模式为MultiExtend。
这是否允许用户使用
控制键从列表框中选择多行?如果是这样,那么如何从
列表框中取回选项?
提前感谢您提供的任何帮助,
Alpha



我想过这样做,但想知道是否有一个属性设置或表单

代码来快速完成。我现在认为使用

数据网格进行列表可能会更好。我根据用户选择的8个单选按钮中的一个来更改列表显示/内容。

。通过使用

数据网格控件来更轻松地进行
多列显示和获取多项选择。


谢谢,

Alpha


" Tim Wilson"写道:

我正在Windows 2000上使用VS 2003进行Windows应用程序。我有


a < blockquote class =post_quotes>我已绑定到数据集表的列表框,source它有3个


列。

我想显示其中2列,scode和sname,作为1


(如果不可能,那么2列将没问题)在列表框中。
列表框可以显示数据集中的2列信息吗?我该怎么做


你可以在DataTable中添加另一列来组合数据将其他两列合二为一。

私有DataTable dataTable1;

....

dataTable1 = new DataTable(" ; MyTable");
dataTable1.Columns.Add(" Column1",typeof(string));
dataTable1.Columns.Add(" Column2",typeof(string));
dataTable1.Columns.Add(" Column3",typeof(string));
dataTable1.Columns.Add(" Column1Column2",typeof(string))。Expression =
" Column1 +' ',''+ Column2" ;;

for(int x = 0; x< 25; x ++)
{/ / dataTable1.Rows.Add(new object [] { FirstName+ x.ToString(),LastName+
x.ToString(),Nothing,null});
}
这个。 listBox1.DisplayMember =" Column1Column2";
this.listBox1。 DataSource = dataTable1;

另外,我将listbox的属性设置为selectionmode为MultiExtend。
这是否允许用户使用

控制键?如果是这样,那我怎样才能从


列表框中取回选项?

是的。您可以使用类似于下面代码的代码来获取所选值。

if(this.listBox1.SelectedItems.Count> 0)
{
int count = this。 listBox1.SelectedItems.Count;
for(int x = 0; x< count; x ++)
{DataRowView rowView = this.listBox1.SelectedItems [x] as DataRowView;
if(rowView!= null)
{MessageBox.Show(rowView.Row [" Column1"]。ToString());
}
}
}

- Tim Wilson
..Net Compact Framework MVP

Alpha <铝*** @ discussions.microsoft.com>在消息中写道
新闻:AF ********************************** @ microsof t.com。 ..


我正在Windows 2000上使用VS 2003进行Windows应用程序。我有


我已绑定到数据集表的列表框,source和它有3个


列。

我想显示其中2列,scode和sname,作为1


(如果不可能,那么2列将没问题)在列表框中。
列表框可以显示数据集中的2列信息吗?我该怎么做


那个?


另外,我设置了列表框的属性选择模式到MultiExtend。
这是否允许用户使用


控制键从列表框中选择多行?如果是这样,那么如何从


列表框中取回选项?


提前感谢您提供的任何帮助,
Alpha




所以你要转向DataGrid控件?如果您需要从数据源进行多列数据显示,那可能会更有意义。


-

Tim Wilson

..Net Compact Framework MVP


news:73 ********************************** @ microsof t.com ...

我想过这样做,但想知道是否有一个属性设置或
表单代码来快速完成。我现在认为使用
数据网格进行列表可能会更好。我根据用户选择的8个单选按钮中的哪一个来更改列表显示/内容。使用
数据网格控件可以更容易地进行多列显示并获得多选项。

谢谢,
Alpha

蒂姆威尔逊写道:

我正在使用Windows 2000上的VS 2003进行Windows应用程序。我

一个

我已绑定到数据集表的列表框,source它有3个


列。

我想显示其中2列,scode和sname,作为1


(如果不可能,那么2列将没问题)在列表框中。
列表框可以显示数据集中的2列信息吗?我如何


这样做?

您可以向DataTable中添加另一列来组合数据
将其他两列合二为一。

私有DataTable dataTable1;

....

dataTable1 = new DataTable(" ; MyTable");
dataTable1.Columns.Add(" Column1",typeof(string));
dataTable1.Columns.Add(" Column2",typeof(string));
dataTable1.Columns.Add(" Column3",typeof(string));
dataTable1.Columns.Add(" Column1Column2",typeof(string))。Expression =
" Column1 +' ',''+ Column2" ;;

for(int x = 0; x< 25; x ++)
{/ / dataTable1.Rows.Add(new object [] { " FirstName" + x.ToString(),
" LastName" + x.ToString()," Nothing",null});
}

listBox1.DisplayMember =" Column1Column2";
this.listBox1.Dat aSource = dataTable1;

另外,我将listbox的属性设置为selectionmode


MultiExtend。这是否允许用户使用

控制键从列表框
中选择多行?如果是这样,那我怎样才能从


列表框中取回选项?

是的。您可以使用类似于下面代码的代码来获取所选的
值。
if(this.listBox1.SelectedItems.Count> 0)
{
int count = this。 listBox1.SelectedItems.Count;
for(int x = 0; x< count; x ++)
{DataRowView rowView = this.listBox1.SelectedItems [x] as DataRowView;
if(rowView!= null)
{MessageBox.Show(rowView.Row [" Column1"]。ToString());
}
}
}

- Tim Wilson
..Net Compact Framework MVP

Alpha <铝*** @ discussions.microsoft.com>在消息中写道
新闻:AF ********************************** @ microsof t.com。 ..


我正在Windows 2000上使用VS 2003进行Windows应用程序。我


有一个

我已绑定到数据集表的列表框,source和它有3个


列。

我想显示其中2列,scode和sname,作为1


(如果不可能,那么2列将没问题)在列表框中。
列表框可以显示数据集中的2列信息吗?我怎样才能


这样做?


另外,我设置了列表框的属性选择模式为


MultiExtend。这是否允许用户使用

控制键从列表框中选择多行



?如果是这样,那么如何从


列表框中取回选项?


提前感谢您提供的任何帮助,
Alpha




Hi,
I''m working on a Windows applicaton with VS 2003 on windows 2000. I have a
listbox that I have binded to a dataset table, "source" which has 3 columns.
I would like to display 2 of those columns, "scode" and "sname", as 1 column
(if not possible then 2 columns will be fine) in the listbox. Can the
listbox display 2 columns information from the dataset and how can I do that?

Also, I set the property of the listbox to selectionmode to MultiExtend.
Would this allow the user to select multiple rows form the listbox using the
control key? If so, then how can I get back the selections from the listbox?

Thanks in advance for any help provided,
Alpha

解决方案

> I''m working on a Windows applicaton with VS 2003 on windows 2000. I have
a

listbox that I have binded to a dataset table, "source" which has 3 columns. I would like to display 2 of those columns, "scode" and "sname", as 1 column (if not possible then 2 columns will be fine) in the listbox. Can the
listbox display 2 columns information from the dataset and how can I do that?

You could add another column to the DataTable that will combine the data of
the other two columns into one.

private DataTable dataTable1;

....

dataTable1 = new DataTable("MyTable");
dataTable1.Columns.Add("Column1", typeof(string));
dataTable1.Columns.Add("Column2", typeof(string));
dataTable1.Columns.Add("Column3", typeof(string));
dataTable1.Columns.Add("Column1Column2", typeof(string)).Expression =
"Column1 + '', '' + Column2";

for (int x = 0; x < 25; x++)
{
dataTable1.Rows.Add(new object[] {"FirstName" + x.ToString(), "LastName" +
x.ToString(), "Nothing", null});
}

this.listBox1.DisplayMember = "Column1Column2";
this.listBox1.DataSource = dataTable1;
Also, I set the property of the listbox to selectionmode to MultiExtend.
Would this allow the user to select multiple rows form the listbox using the control key? If so, then how can I get back the selections from the listbox?

Yes. You can use code similar to the code below to get the selected values.

if (this.listBox1.SelectedItems.Count > 0)
{
int count = this.listBox1.SelectedItems.Count;
for (int x = 0; x < count; x++)
{
DataRowView rowView = this.listBox1.SelectedItems[x] as DataRowView;
if (rowView != null)
{
MessageBox.Show(rowView.Row["Column1"].ToString());
}
}
}

--
Tim Wilson
..Net Compact Framework MVP

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com... Hi,
I''m working on a Windows applicaton with VS 2003 on windows 2000. I have a listbox that I have binded to a dataset table, "source" which has 3 columns. I would like to display 2 of those columns, "scode" and "sname", as 1 column (if not possible then 2 columns will be fine) in the listbox. Can the
listbox display 2 columns information from the dataset and how can I do that?
Also, I set the property of the listbox to selectionmode to MultiExtend.
Would this allow the user to select multiple rows form the listbox using the control key? If so, then how can I get back the selections from the listbox?
Thanks in advance for any help provided,
Alpha



I thought about doing that but wonder if there is a property setting or form
code to do that quick. I now think that it might be better to use the
datagrid for listing. I change the listing display/content depending on
which one of the 8 radio buttons that the user selects. Is it easier to do
multicolumn display and getting the multi-selections back by using the
datagrid control instead.

Thanks,
Alpha

"Tim Wilson" wrote:

I''m working on a Windows applicaton with VS 2003 on windows 2000. I have


a

listbox that I have binded to a dataset table, "source" which has 3


columns.

I would like to display 2 of those columns, "scode" and "sname", as 1


column

(if not possible then 2 columns will be fine) in the listbox. Can the
listbox display 2 columns information from the dataset and how can I do


that?

You could add another column to the DataTable that will combine the data of
the other two columns into one.

private DataTable dataTable1;

....

dataTable1 = new DataTable("MyTable");
dataTable1.Columns.Add("Column1", typeof(string));
dataTable1.Columns.Add("Column2", typeof(string));
dataTable1.Columns.Add("Column3", typeof(string));
dataTable1.Columns.Add("Column1Column2", typeof(string)).Expression =
"Column1 + '', '' + Column2";

for (int x = 0; x < 25; x++)
{
dataTable1.Rows.Add(new object[] {"FirstName" + x.ToString(), "LastName" +
x.ToString(), "Nothing", null});
}

this.listBox1.DisplayMember = "Column1Column2";
this.listBox1.DataSource = dataTable1;

Also, I set the property of the listbox to selectionmode to MultiExtend.
Would this allow the user to select multiple rows form the listbox using


the

control key? If so, then how can I get back the selections from the


listbox?

Yes. You can use code similar to the code below to get the selected values.

if (this.listBox1.SelectedItems.Count > 0)
{
int count = this.listBox1.SelectedItems.Count;
for (int x = 0; x < count; x++)
{
DataRowView rowView = this.listBox1.SelectedItems[x] as DataRowView;
if (rowView != null)
{
MessageBox.Show(rowView.Row["Column1"].ToString());
}
}
}

--
Tim Wilson
..Net Compact Framework MVP

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...

Hi,
I''m working on a Windows applicaton with VS 2003 on windows 2000. I have


a

listbox that I have binded to a dataset table, "source" which has 3


columns.

I would like to display 2 of those columns, "scode" and "sname", as 1


column

(if not possible then 2 columns will be fine) in the listbox. Can the
listbox display 2 columns information from the dataset and how can I do


that?


Also, I set the property of the listbox to selectionmode to MultiExtend.
Would this allow the user to select multiple rows form the listbox using


the

control key? If so, then how can I get back the selections from the


listbox?


Thanks in advance for any help provided,
Alpha




So you''re moving to the DataGrid control? That might make more sense if you
need to do multi-column data display from a data source.

--
Tim Wilson
..Net Compact Framework MVP

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:73**********************************@microsof t.com...

I thought about doing that but wonder if there is a property setting or form code to do that quick. I now think that it might be better to use the
datagrid for listing. I change the listing display/content depending on
which one of the 8 radio buttons that the user selects. Is it easier to do multicolumn display and getting the multi-selections back by using the
datagrid control instead.

Thanks,
Alpha

"Tim Wilson" wrote:

I''m working on a Windows applicaton with VS 2003 on windows 2000. I have

a

listbox that I have binded to a dataset table, "source" which has 3


columns.

I would like to display 2 of those columns, "scode" and "sname", as 1


column

(if not possible then 2 columns will be fine) in the listbox. Can the
listbox display 2 columns information from the dataset and how can I

do that?

You could add another column to the DataTable that will combine the data of the other two columns into one.

private DataTable dataTable1;

....

dataTable1 = new DataTable("MyTable");
dataTable1.Columns.Add("Column1", typeof(string));
dataTable1.Columns.Add("Column2", typeof(string));
dataTable1.Columns.Add("Column3", typeof(string));
dataTable1.Columns.Add("Column1Column2", typeof(string)).Expression =
"Column1 + '', '' + Column2";

for (int x = 0; x < 25; x++)
{
dataTable1.Rows.Add(new object[] {"FirstName" + x.ToString(), "LastName" + x.ToString(), "Nothing", null});
}

this.listBox1.DisplayMember = "Column1Column2";
this.listBox1.DataSource = dataTable1;

Also, I set the property of the listbox to selectionmode to

MultiExtend. Would this allow the user to select multiple rows form the listbox using the

control key? If so, then how can I get back the selections from the


listbox?

Yes. You can use code similar to the code below to get the selected values.
if (this.listBox1.SelectedItems.Count > 0)
{
int count = this.listBox1.SelectedItems.Count;
for (int x = 0; x < count; x++)
{
DataRowView rowView = this.listBox1.SelectedItems[x] as DataRowView;
if (rowView != null)
{
MessageBox.Show(rowView.Row["Column1"].ToString());
}
}
}

--
Tim Wilson
..Net Compact Framework MVP

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...

Hi,
I''m working on a Windows applicaton with VS 2003 on windows 2000. I

have a

listbox that I have binded to a dataset table, "source" which has 3


columns.

I would like to display 2 of those columns, "scode" and "sname", as 1


column

(if not possible then 2 columns will be fine) in the listbox. Can the
listbox display 2 columns information from the dataset and how can I

do that?


Also, I set the property of the listbox to selectionmode to

MultiExtend. Would this allow the user to select multiple rows form the listbox


using the

control key? If so, then how can I get back the selections from the


listbox?


Thanks in advance for any help provided,
Alpha




这篇关于如何显示多列并从lis中获取多项选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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