Click here to Skip to main content
Rate this: bad
good
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.
 
Or
 
"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;
            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 27-Mar-13 3:10am
Edited 27-Mar-13 3:13am
v2
Comments
ThePhantomUpvoter at 27-Mar-13 8:13am
   
Okay.... and the question and/or problem is.....?
Abhinavkpit007 at 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 at 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 at 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 at 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
0 OriginalGriff 406
1 /\jmot 180
2 Suraj Sahoo | Coding Passion 170
3 BillWoodruff 159
4 Afzaal Ahmad Zeeshan 154
0 OriginalGriff 8,344
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,634
3 Maciej Los 5,024
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2014
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