datagrid without dataset

Posted on 2007-07-31
Last Modified: 2013-11-07
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
Question by:Micki-Weaver
    LVL 96

    Accepted Solution

    It is easier to create an in-memory DataTable, and bind the DataGrid to that.


    Author Comment

    thanks if you happen to have an example
    LVL 96

    Expert Comment

    by:Bob Learned

            private DataTable FillDataTable()
                DataTable dt = new DataTable();
                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;


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now