Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I programmatically add a row to a WPF datagrid?

Tags:

wpf

datagrid

I just want to add a new row, I have my datasource in objects in which I need to do some processing. i need something like below for wpf datagrid...

DataRow row = dataTable.NewRow();
foreach (NavItem item in record.Items)
{
    row[item.FieldNo.ToString()] = item.RecordValue;
}
dataTable.Rows.Add(row);
like image 530
Kervin Ramen Avatar asked Dec 17 '25 22:12

Kervin Ramen


1 Answers

You should be using an ObservableCollection<NavItem> as the datagrid source. Then simply adding a new element to your collection will add it to the datagrid.

See this MSDN article.

like image 82
Mart Avatar answered Dec 20 '25 01:12

Mart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!