vb.net 将数据从数组存储到 datagridview

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18845571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:06:04  来源:igfitidea点击:

Store data from array to datagridview

vb.netdatagridview

提问by user2194838

There is an array gGroupArray of type structure GroupType

有一个类型结构 GroupType 的数组 gGroupArray

 Public Structure GroupType
    Dim bChecked As Boolean
    Dim iCategoryID As Short
    Dim tProductGroup As String
 End Structure

 Public gGroupArray() As GroupType

Data is stored in gGroupArray. There is data grid view named as GroupGrid

数据存储在 gGroupArray 中。有一个名为 GroupGrid 的数据网格视图

      With GroupGrid
        Dim objCB As New DataGridViewCheckBoxColumn
        With objCB
            .Name = "CB"
        End With
        .Columns.Add(objCB)

        Dim objProductGroup As New DataGridViewTextBoxColumn
        With objProductGroup
            .Name = "ProductGroup"
        End With
        .Columns.Add(objProductGroup)

        Dim objCategoryId As New DataGridViewTextBoxColumn
        With objCategoryId
            .Name = "CategoryID"
        End With
        .Columns.Add(objCategoryId)
    End With
    GroupGrid.RowCount = UBound(gGroupArray)
    GroupGrid.Rows.Add(GroupGrid.RowCount)

I have to store the gGroupArray data into GroupGrid. How this can be done.

我必须将 gGroupArray 数据存储到 GroupGrid 中。如何做到这一点。

Thanks

谢谢

采纳答案by Maher

First create threecolumns, then use this code:

首先创建列,然后使用以下代码:

Public Sub Load_Items(ByRef Array() As GroupType, ByRef DataGrid As DataGridView)
    For Each Item As GroupType In Array
        With Item
            DataGrid.Rows.Add(.bChecked, .iCategoryID, .tProductGroup)
        End With
    Next
End Sub

the first parameter is gGroupArrayand the second is your DataGridView name.

第一个参数是gGroupArray,第二个是你的DataGridView name

Tell me if it works! :)

告诉我它是否有效!:)