How to add data to DataGridView

后端 未结 5 1774
野的像风
野的像风 2021-01-02 10:09

I\'m having a Structure like

 X={ID=\"1\", Name=\"XX\",
    ID=\"2\", Name=\"YY\" };

How to dump this data to a DataGridView o

5条回答
  •  一向
    一向 (楼主)
    2021-01-02 10:13

    My favorite way to do this is with an extension function called 'Map':

    public static void Map(this IEnumerable source, Action func)
    {
        foreach (T i in source)
            func(i);
    }
    

    Then you can add all the rows like so:

    X.Map(item => this.dataGridView1.Rows.Add(item.ID, item.Name));
    

提交回复
热议问题