datagrid without dataset

can someone give a walk threw on how to use a datagrid with out a data set, some code would be nice on adding columns and rows
Micki-WeaverAsked:
Who is Participating?
 
Bob LearnedCommented:
It is easier to create an in-memory DataTable, and bind the DataGrid to that.

Bob
0
 
Micki-WeaverAuthor Commented:
thanks if you happen to have an example
0
 
Bob LearnedCommented:
Example:

        private DataTable FillDataTable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("City");
            dt.Columns.Add("Rating", typeof(int));

            this.AddRow(dt, "Boston", 80);
            this.AddRow(dt, "New York", 40);
            this.AddRow(dt, "Los Angeles", 65);
            this.AddRow(dt, "San Francisco", 10);
            this.AddRow(dt, "Cincinnati", 45);
            this.AddRow(dt, "Cleveland", -10);

            return dt;
        }

        private void AddRow(DataTable dt, string city, int rating)
        {
            DataRow dr = dt.NewRow();
            dr["City"] = city;
            dr["Rating"] = rating;
            dt.Rows.Add(dr);
        }

Bob
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.