Click here to Skip to main content
15,915,094 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,

I have datagrid of WPF with the name dgSchedule.I already have rows in datagrid.I want to add new row dynamically to the datagrid.

I have tried following but new row wasn't displayed in datagrid.

What I have tried:

C#
ObservableCollection<states> stlist = new ObservableCollection<states>();
foreach (States row in dgSchedule.Items)
    stlist.Add(row);

stlist.Add(s);//Where s is empty list
dgSchedule = null;
dgSchedule = new DataGrid();
dgSchedule.ItemsSource = stlist;
Posted
Updated 26-Apr-16 1:27am
v3

1 solution

Hi, Just assign a property of type DataTable to the DataGrid as DataContext, implement INotifyPropertyChanged for this property. Now just create a new row in the table, it will reflect on the datagrid.
 
Share this answer
 
Comments
Member 12166125 28-Apr-16 6:44am    
Thanks.

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