[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

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
0
Micki-Weaver
Asked:
Micki-Weaver
  • 2
1 Solution
 
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

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now