Programmatically populate grid

  • Thread starter Thread starter Tim Kelley
  • Start date Start date
T

Tim Kelley

Is it possible to populate a grid using code (not binding it to a
datasource). Is there something like an additem method?

Thanks,
 
Tim,

No, there isn't. You need to find a class that implements IList and
then bind to that.

DataSet classes are disconnected data, meaning that you don't need a
database in order to use them. They also have designer support, so you
should just use that in your program and bind to that (populating that
programatically).

Hope this helps.
 
I gave that a try. I created my dataset and datatable and populated it
with the data I need.
I bound the dataviewgrid to the dataset, but no records show in my grid. I
have checked the datatable and there are actually records in the table. Am
I missing something? Here is the code I am using:

DataSet dsgrid = new DataSet();

DataTable workTable = new DataTable();

dsgrid.Tables.Add("tablename");

workTable.Columns.Add("field1", typeof(String));

workTable.Columns.Add("field2", typeof(String));

workTable.Columns.Add("field3", typeof(String));

code to populate table

dataGridView1.DataSource = dsgrid.Tables[0];


Thanks,


Nicholas Paldino said:
Tim,

No, there isn't. You need to find a class that implements IList and
then bind to that.

DataSet classes are disconnected data, meaning that you don't need a
database in order to use them. They also have designer support, so you
should just use that in your program and bind to that (populating that
programatically).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tim Kelley said:
Is it possible to populate a grid using code (not binding it to a
datasource). Is there something like an additem method?

Thanks,
 

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

Back
Top