如何将数据绑定到列表视图中的多个列?

时间:2021-07-14 22:58:14

I have a datasource that I want to bind to a listview that has multiple columns. How do I bind my datasource to that listview

我有一个数据源,我想绑定到具有多列的列表视图。如何将我的数据源绑定到该列表视图

Here is some pseudo code that doesn't work to help illustrate what I am trying to do:

这里有一些伪代码无法帮助说明我想要做的事情:

MyDataTable dt = GetDataSource();
ListView1.DataBindings.Add("Column1.Text", dt, "MyDBCol1");
ListView1.DataBindings.Add("Column2.Text", dt, "MyDBCol2");

-- edit --

- 编辑 -

Sorry, I forgot to mention it was winforms.

对不起,我忘了提到它是winforms。

4 个解决方案

#1


3  

It seems there is a lacuna in functionality of WinForms ListView control (thought it's possible to databind new WPF ListBox).

似乎WinForms ListView控件的功能存在缺陷(认为可以对新的WPF ListBox进行数据绑定)。

This article by Nick Karnik describes how to add databinding capability to custom control inherited from WinForms ListView - Data binding a ListView.

本文由Nick Karnik介绍了如何将数据绑定功能添加到从WinForms ListView继承的自定义控件 - 数据绑定ListView。

#2


0  

Can you please clarify whether this is winforms vs webforms? Both have a ListView. From the DataBindings.Add I'm assuming winforms.

你能澄清这是winforms vs webforms吗?两者都有一个ListView。从DataBindings.Add我假设winforms。

Would DataGridView be a pragmatic option? This will support multi-column binding out of the box?

DataGridView会是一个实用的选择吗?这将支持开箱即用的多列绑定?

#3


0  

Listview has no Datasource, Items must be added manually.

Listview没有数据源,必须手动添加项目。

I would suggest to use the DatagridView instead of the Listview.
Particularly if you have a lot of items.

我建议使用DatagridView而不是Listview。特别是如果你有很多物品。

#4


-3  

Check out this reference on binding datasource to listview. Is that what you were looking for?

查看有关将数据源绑定到listview的此参考。那是你在找什么?

#1


3  

It seems there is a lacuna in functionality of WinForms ListView control (thought it's possible to databind new WPF ListBox).

似乎WinForms ListView控件的功能存在缺陷(认为可以对新的WPF ListBox进行数据绑定)。

This article by Nick Karnik describes how to add databinding capability to custom control inherited from WinForms ListView - Data binding a ListView.

本文由Nick Karnik介绍了如何将数据绑定功能添加到从WinForms ListView继承的自定义控件 - 数据绑定ListView。

#2


0  

Can you please clarify whether this is winforms vs webforms? Both have a ListView. From the DataBindings.Add I'm assuming winforms.

你能澄清这是winforms vs webforms吗?两者都有一个ListView。从DataBindings.Add我假设winforms。

Would DataGridView be a pragmatic option? This will support multi-column binding out of the box?

DataGridView会是一个实用的选择吗?这将支持开箱即用的多列绑定?

#3


0  

Listview has no Datasource, Items must be added manually.

Listview没有数据源,必须手动添加项目。

I would suggest to use the DatagridView instead of the Listview.
Particularly if you have a lot of items.

我建议使用DatagridView而不是Listview。特别是如果你有很多物品。

#4


-3  

Check out this reference on binding datasource to listview. Is that what you were looking for?

查看有关将数据源绑定到listview的此参考。那是你在找什么?