views:

10686

answers:

2

Hello Guys,

i m new to WPF. i just wana know how should we add Columns & rows programatically to DataGrid in WPF. The way we used to do it in windows forms. create table columns , rows & bind it to datagrid.

i believe WPF datagrid is bit different the one used in ASP.net & Windows form ( correct me if i m wrong).

Basically i have No Of Rows & Columns which i need to draw in datagrid so that user can edit the data in the cells. let me know if you have any ideas.

Andy

+5  A: 

To programatically add a row:

DataGrid.Items.Add(new DataItem());

To programatically add a column:

DataGrid.Columns.Add(new DataGridTextColumn());

Check out this post on the WPF DataGrid discussion board for more information.

John Myczek
A: 

I'm using DataGrid.Items.Add(new DataItem()); with the namespace 'System.web.ui.webcontrols' and still DataItem isn´t recognized by the program. I use ItemsSource bindings.

I was wandering if anyone knows why this happens.

Thank you

You probably should post this as a new question, not as an answer to an old question. In the upper right there is a "Ask Question" button that allows you to ask a new question.
sth