InertiaM
Well-known member
I have a class (called cProductionItem) which has three properties, intID, strBarcode and strDescription. I will eventually need more properties in this class.
I need to populate a DataGridView with these items. Having read one of jmcilhinney's posts, the fastest way to do this is to make a DataTable with all the information, then set the DGV DataSource to be the DataTable.
What I currently have is
I noticed that a DataRow has an ItemArray property. Is there a simple way to write something like :-
or am I best to keep adding the items individually?
I need to populate a DataGridView with these items. Having read one of jmcilhinney's posts, the fastest way to do this is to make a DataTable with all the information, then set the DGV DataSource to be the DataTable.
What I currently have is
VB.NET:
Dim table As DataTable = New DataTable
table.Columns.Add("ID")
table.Columns.Add("BARCODE")
table.Columns.Add("DESCRIPTION")
Dim row As DataRow
For Each _ProductionItem As cProductionItem In allProductionItems
row = table.NewRow()
row.Item(0) = _ProductionItem.intID
row.Item(1) = _ProductionItem.strBarcode
row.Item(2) = _ProductionItem.strDescription
table.Rows.Add(row)
Next _ProductionItem
I noticed that a DataRow has an ItemArray property. Is there a simple way to write something like :-
VB.NET:
row.ItemArray = {_ProductionItem.intID, _ProductionItem.strBarcode, _ProductionItem.strDescription}
or am I best to keep adding the items individually?