0

WPF window in C# doesn't have option of Inserting something into DataGrid immediately, like as WinForms Form

DataGridView.Rows.Add(whatever)

What is alternative for this code 👆?
So how can I insert an array into DataGridView in WPF window?

1
  • Create an List. For eg: List<Datatype> mylist = new List<Datatype> Add some data to your List: mylist.Add(blah) Bind this to your datagrid in C#: datagrid.ItemsSource = mylist Commented Jul 14, 2017 at 13:50

2 Answers 2

1

You can actually add objects directly to the Items property of the DataGrid:

dataGrid.Items.Add(whatever);

But if you want to be able to edit the items, you should set or bind the ItemsSource property to an IList:

dataGrid.ItemsSource = new List<object> { whatever };
Sign up to request clarification or add additional context in comments.

Comments

0

You need to bind the DataGrid to an ObservableCollection. If you insert into the ObservableCollection, it'll appear on the UI

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.