By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,701 Members | 1,711 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,701 IT Pros & Developers. It's quick & easy.

Populating DataGrid

P: n/a

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.


Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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

"fripper" <fr*****@insightbb.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

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.

Nov 21 '05 #2

P: n/a
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

"fripper" <fr*****@insightbb.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

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.

Nov 21 '05 #3

P: n/a
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.

"Chris" <chris@No_Spam_Please.com> wrote in message
news:OJ**************@TK2MSFTNGP12.phx.gbl...
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

"fripper" <fr*****@insightbb.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

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.


Nov 21 '05 #4

P: n/a
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.

"Chris" <chris@No_Spam_Please.com> wrote in message
news:OJ**************@TK2MSFTNGP12.phx.gbl...
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

"fripper" <fr*****@insightbb.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

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.


Nov 21 '05 #5

P: n/a
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.

"fripper" wrote:

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.


Nov 21 '05 #6

P: n/a
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.

"fripper" wrote:

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.


Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.