0

I'm writing application in .NET 4.5 framework. I use DataGrid to show data. I want to add new text collumn and to each row I want to assign text value to cell in this collumn. I don't know How to do this. I don't know how to bind data, or can I manually change cell content? That would be most convinient for me.

Saajuu
  • 107
  • 1
  • 10

1 Answers1

0

Here is one way to populate the DataGrid programatically:

public class Row
{
    public int Id { get; set; }
    public string Name { get; set; }
}

MyDataGrid.Columns.Add(new DataGridTextColumn { Header = "Id", Binding = new Binding("Id"), Width = 100 });
MyDataGrid.Columns.Add(new DataGridTextColumn { Header = "Name", Binding = new Binding("Name"), Width = 100 });
MyDataGrid.Items.Add(new Row { Id = 1, Name = "Mr. Anderson"});
MyDataGrid.Items.Add(new Row { Id = 2, Name = "John Smith"});
Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169