Populating DataGrid

F

fripper

I want to populate the cells of a DataGrid at run time. I don't want to
bind a database to it I simply want to do some calculations and put results
into the grid programmatically. I did this in VB 6.0 using the FlexGrid
control but the I cannot figure out how to specify the row/column of the
cell I want to set in the .Net DataGrid control and how to set its value.

Thanks for your help.
 
C

Chris

The way to do this is by setting up a DataTable at runtime and populating
that, then bind that to the datagrid.

Something like this

Dim DT as DataTable
DT.Columns.Add("NewColumn1")
DT.Columns.Add("NewColumn2")
for ii = 0 to 100
Dim DR as DataRow = DT.NewRow
DR.Item(0) = ii
DR.Item(1) = "Something"
DT.Rows.Add(DR)
next
DataGrid1.Datasource = DT

I didn't write that in the IDE so it might not be perfect, but that's the
idea right there.

Hope it helps
Chris
 
F

fripper

Thanks very much Chris ... I am beginning to get a handle on the DataGrid
control. I am sure that buried in the humongous help files that Microsoft
provides is an explanation of this but I sure couldn't find it! Your clear,
concise explanation helps a lot.
 
G

Guest

You can put your data into a class then the collection of classes into an
arraylist or an array and bind the array or arraylist to the DataGrid.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top