以编程方式填充 DataGridView [英] Programmatically populate DataGridView
本文介绍了以编程方式填充 DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 DataGridView,我正在尝试使用 For 循环填充它:
I have a DataGridView that I'm trying to populate using a For loop:
Dim serverName As String = SQLServerName + "\" + Instance
Dim server As Server = New Server(serverName)
Dim Datatable1 As New DataTable
For Each database As Database In server.Databases
Dim row As DataRow = Datatable1.NewRow
row("Database") = database.Name
row("Version") = DBVersionCheck(serverName, database.Name)
row("Status") = My.Resources.My_Image
Datatable1.Rows.Add(row)
Next
DataGridView1.DataSource = Datatable1
DGV 是由设计师设计的(列、布局等).使用上述 DGV 不会填充.我为此使用了 ListView,但我需要子项中的图像,因此已切换到使用 DGV.有什么建议吗?
The DGV has been designed with the designer (columns, layout etc). Using the above the DGV does not populate. I was using a ListView for this but I need images in a subitem so have switched to using a DGV. Any advice?
推荐答案
您需要将列添加到 DataTable
.
我有一些代码(C#),但你应该能够转换它:
I've got some code (which is C#) but you should be able to convert it:
var columnSpec = new DataColumn
{
DataType = string,
ColumnName = "Database Name"
};
this.dataTable.Columns.Add(columnSpec);
这将添加一个名为数据库名称"的 string
类型的列.
which will add a column of type string
with the name "Database Name".
这篇关于以编程方式填充 DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文