Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

Or

"Can you suggest me with a way where i should look in order to to "Draw" a Table using DrawingVisual class"
C#
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;
            drawingCanvas.Children.Add(dt);
            Canvas.SetTop(dt, graphicsTable.Rectangle.Top);
            Canvas.SetLeft(dt, graphicsTable.Rectangle.Left);
            dt.Width = dt.Width;
            dt.Height = dt.Height;
            dt.Focus();
        }
//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
Updated 27-Mar-13 2:13am
v2
Comments
[no name] 27-Mar-13 8:13am    
Okay.... and the question and/or problem is.....?
Abhinav_Sharma 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!!!!!!!!!
[no name] 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.
Abhinav_Sharma 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.........
[no name] 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900