Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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?
List<Datatype> mylist = new List<Datatype>
mylist.Add(blah)
datagrid.ItemsSource = mylist
You can actually add objects directly to the Items property of the DataGrid:
Items
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:
ItemsSource
IList
dataGrid.ItemsSource = new List<object> { whatever };
Add a comment
You need to bind the DataGrid to an ObservableCollection. If you insert into the ObservableCollection, it'll appear on the UI
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
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