How to use DataRow ItemArray property

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
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

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?
 
ItemArray is an array of type Object:
VB.NET:
row.ItemArray = New Object() {_ProductionItem.ID, _ProductionItem.Barcode, _ProductionItem.Description}
Do not use Hungarian notation. intID > ID etc.
 
Back
Top