Click here to Skip to main content
12,401,324 members (39,671 online)
Rate this:
Please Sign up or sign in to vote.
I am currently working on a custom canvas and in that i have to add a table,So i thought dataGrid would be fine. SO i Want to create a "Table" from "Datagrid" by which user can add a table to the canvas at runtime.

Till now, I have tried to Populate DataGrid With a list and succeded.

How Can I add Columns to a Datagrid at runtime,such that the number of columns and header value Would be taken from the user at runtime using a textbox and based on the value of the textbox the datagrid should add columns and header value.

Actually I want to develop a Table in which user passes the no of columns and the column header and the table should be generated.


"Can you suggest me with a way where i should look in order to to "Draw" a Table using DrawingVisual class"
It is a part of GraphicsTable Class
//Custom Classes "DrawingCanvas & GraphicsTable" 
     public void CreateDataGrid(GraphicsTable graphicsTable, DrawingCanvas drawingCanvas)
            dt = new DataGrid();
            dt.Name = "Data";
            dt.ItemsSource = person();
            dt.AllowDrop = true;
            dt.AutoGenerateColumns = true;
            dt.Height = graphicsTable.Rectangle.Height;
            dt.Width = graphicsTable.Rectangle.Width;
            Canvas.SetTop(dt, graphicsTable.Rectangle.Top);
            Canvas.SetLeft(dt, graphicsTable.Rectangle.Left);
            dt.Width = dt.Width;
            dt.Height = dt.Height;
//I have just tried to add dome dummy data to the datagrid.

        public List person()
            List peep = new List();
            peep.Add(new Person() {});
            return peep;
   public class Person
        private string name;
        private double salary;
        public string Names
            get { return name; }
            set { name = value; }
        public double Salary
            get { return salary; }
            set { salary = value; }
Posted 27-Mar-13 2:10am
Updated 27-Mar-13 2:13am
ThePhantomUpvoter 27-Mar-13 8:13am
Okay.... and the question and/or problem is.....?
Abhinavkpit007 27-Mar-13 8:20am
@ThePhantomUpvoter:Thanks for ur reply.
As mentioned above I want to create a table based input provided by the user in the textbox,how can I do it??Can u suggest me a path to look on....

Any help is welcomed!!!!!!!!!
ThePhantomUpvoter 27-Mar-13 8:25am
So create a table then. A List would never work for what you want so use a table. It's as simple as that. You can add columns to the table and then bind the table to the grid.
Abhinavkpit007 27-Mar-13 8:38am
Srry buddy!! but for that purpose i asked the question "How to create such a Table?"
"How to create a table from Datagrid?"

I tried using DrawingVisual but not able to add text to the table....

So Can u give some suggestions.........
ThePhantomUpvoter 27-Mar-13 8:42am
Did you try DataTable dt = new DataTable();?

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100