Click here to Skip to main content
15,851,387 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
User input in textboxs number of rows and columns and I have to create editable DataGrid with this size. How can I do this?

DataGrid table = new DataGrid();
for (int i = 0; i < 5; i++)
    table.Columns.Add(new DataGridTextColumn());
    table.CanUserAddRows = true;
    table.CanUserDeleteRows = true;
    table.IsReadOnly = false;
    table.Items.Add(new DataGridTextColumn());

With this code I create table with size that I need, but when I try to edit cell, I'he got "editItem not allowed" error.

if I do this code I'he got columns with TextBox fields.
DataGrid table = new DataGrid();
List<TextBox> tableData = new List<TextBox>(5);
table.ItemsSource = tableData;

Any help?
Lion Lion 11-Jun-18 10:31am    

1 solution

Below i mention link for your reference please check it..

WPF DataGrid Practical Examples[^]

if you finding solution then mark as answered..


Happy coding....

This is solution regarding your second query..

yes you are right....yes it is possible..

public override void Execute(object parameter)
    var context = parameter as GenerateColumnContext;
    DataGridTextColumn column = new DataGridTextColumn();
    if (context.PropertyName == "Country")
        column.Header = "header for Country";
    context.Result = column;

May be this can help you further...


If you getting your answer related to this post then please mark as answered..
Share this answer
Dmitrii Grishchenko 29-May-13 0:50am    
Thanks for your reply, but in this examples using database, and I working without it. I just want to create table which user can fill by himself.
renish patel 29-May-13 2:30am    
ok nop, I suggest one msdn discussion for it..please check it out..

may be that solve your problem.if you finding solution then mark as answered..


Happy coding....
Dmitrii Grishchenko 29-May-13 6:49am    
Thanks. Rows are objects and columns are object's field. This means, that if I want N columns in datagrid, I have to use object with N fields, right? But N set by user and can change. Is it possible to create class with variable number of fields?
Dmitrii Grishchenko 2-Jun-13 23:58pm    
Thank you. If I right, your second solution use Telerik? If there other ways? Without Teletik.
Dmitrii Grishchenko 3-Jun-13 4:38am    
Thanks for help, but I think I was wrong from the very beginning. DataGrid is't right control for my task, so I created editable table with Grid control, in which every cell is a TextBox control, and it works for me

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