dataGridView demo

can I get a demo on how to load a DataGridView  (note not dataGrid)

so far:
1. make dataSet
2. make dataTable - connect to dataSet
3. make dataColumn - connect to dataTable
4. make dataRows - connect to dataTable
5. make the dataSet the DataGridView.DataSource

thanks
Micki-WeaverAsked:
Who is Participating?
 
Priest04Commented:
To create a DataTable (example from MSDN)

DataTable workTable = new DataTable("Customers"); // this line creates DataTable object

DataColumn workCol = workTable.Columns.Add("CustID", typeof(Int32)); // this adds first column, type integer
workCol.AllowDBNull = false; // this line forbids null value to be added to this first column
workCol.Unique = true; // this line is saying that every value in this first column will be unique

workTable.Columns.Add("CustLName", typeof(String)); // add 2nd column, type string
workTable.Columns.Add("CustFName", typeof(String)); // add 3rd column, type string
workTable.Columns.Add("Purchases", typeof(Double)); // add 4th column, type double

Now that we have created DataTable, lets add some values in it

DataRow workRow = workTable.NewRow(); // we do this to create a new row that we will later insert in DataTable

workRow["CustID"] = 1; // we add value to 1st column
workRow["CustLName"] = "Smith"; // we add value to 2nd column
workRow["CustFName"] = "John"; // we add value to 3rd column
workRow["Purchases"] = 925.30; // we add value to 4th column

workTable.Rows.Add(workRow); // we finally add this row to DataTable

To add this DataTable to DataSet, we first need to create DataSet

DataSet ds = new DataSet(); // we create new DataSet object
ds.Tables.Add(workTable); // we add DataTable object that we previously created to DataSet

Now, to set this DataTable to datagridview datasource

DataGridView1.DataSource = workTable;

or, using DataSet we just created

DataGridView1.DataSource = ds.Tables["Customers"];

Here are link were you can read more

http://msdn2.microsoft.com/en-us/library/hfx3s9wd.aspx
http://msdn2.microsoft.com/en-us/library/z16c79x4.aspx


Goran
0
 
Priest04Commented:
Do you mean that you want to create dataset, datatable and datacolumn manually through code, and also add data manually through code (do not want to pull data from database?

Goran
0
 
Micki-WeaverAuthor Commented:
correct, all by hand, I may even do the dataGridView by hand but I can do that.
0
 
Micki-WeaverAuthor Commented:
thanks that works
0
 
Priest04Commented:
You are welcome

Goran
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.