如何使用DataGridView绑定字符串数组 [英] how to bind an array of string with DataGridView

查看:405
本文介绍了如何使用DataGridView绑定字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我正在C#Windows应用程序VS2005上工作,我选择了文本文件,然后以字符串数组形式输入文件,现在我必须在数据网格视图中逐行输入数组,但是我不能做同样的事情
在数组中,我现在具有的行数和列数现在我想将所有包含列的行放在数据网格视图中
有人可以帮我吗

Hi All
I am working on C# windows application VS2005 where I selected text file and enter the file in string array now I have to enter row by row of the array in a data grid view but I am not able to do the same
In the array I have number of rows with number of columns now I want to put all the rows with the columns in the data grid view
Can any one help me please

推荐答案

如此处所述

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx [ ^ ]


DataGridView 类支持标准Windows窗体数据绑定模型.这意味着数据源可以是实现以下接口之一的任何类型:

IList接口,包括one-dimensional arrays.
IListSource 接口,例如DataTable和DataSet类.
IBindingList接口,例如BindingList< t>,课.
IBindingListView 接口,例如BindingSource类.


Array类实现IList接口.因此,您可以将DataGridView.DataSource设置为数组.
As explained here

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx[^]


The DataGridView class supports the standard Windows Forms data-binding model. This means the data source can be of any type that implements one of the following interfaces:

The IList interface, including one-dimensional arrays.
The IListSource interface, such as the DataTable and DataSet classes.
The IBindingList interface, such as the BindingList<t> class.
The IBindingListView interface, such as the BindingSource class.


The Array class implements IList interface. Hence, you can set DataGridView.DataSource to your array.


这篇关于如何使用DataGridView绑定字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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