2

So in WinForms you can easily add a row, for example

dataGridView1.Rows.Add(user.Handle, c);

But in WPF, when I try to use a DataGrid there is no 'Rows' property. Is there any way to do this in WPF that doesn't consist of an insane amount of lines of code or a lot of messing with XAML?

3

2 Answers 2

3

if you are not binding it to any source (i.e DataTable, List etc) try

dataGridView1.Items.Add(new DataItem { Column1 = "a", Column2 = "b" });
Sign up to request clarification or add additional context in comments.

Comments

2

It's this simple :

// add a row    
DataGrid.Items.Add(new DataItem()); 

// add a column
DataGrid.Columns.Add(new DataGridTextColumn()); 

Please refer this link for more, http://wpf.codeplex.com/Thread/View.aspx?ThreadId=34065

Or if you don't like to add rows directly like that, use a collection as source. Bind the Grid to a List (Observable collection). Add items to that list. Result: new rows show up in the grid.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.