开发者

Programmatically populate DataGridView

开发者 https://www.devze.com 2023-01-17 18:56 出处:网络
I have a DataGridView that I\'m trying to populate using a For loop: Dim serverName As String = SQLServerName + \"\\\" + Instance

I have a DataGridView that I'm trying to populate using a For loop:

    Dim serverName As String = SQLServerName + "\" + Instance
   开发者_JAVA百科 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

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?


You need to add the columns to the DataTable.

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);

which will add a column of type string with the name "Database Name".

0

精彩评论

暂无评论...
验证码 换一张
取 消