You can use the WPF DataGrid control. It displays a grid of cells that correspond to a collection of objects (rows) containing properties (columns). You need to provide a data warehouse - a set of objects. The number of objects in the collection (collection counter) will determine the number of rows in the grid. DataGrid supports data editing in the user interface.
This example defines three columns and associates them with the A, B, and C properties of the data object.
<DataGrid AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" Name="dataGrid1" VerticalAlignment="Top" Width="200"> <DataGrid.Columns > <DataGridTextColumn Binding="{Binding Path=A}" MinWidth="50" /> <DataGridTextColumn Binding="{Binding Path=B}" MinWidth="50" /> <DataGridTextColumn Binding="{Binding Path=C}" MinWidth="50" /> </DataGrid.Columns> </DataGrid>
You need to assign (in code or using data binding) a collection of objects with these properties to the ItemsSource DataGrid property, like to any other ItemsControl element. Something like that:
public partial class MainWindow: Window { public class DataObject { public int A { get; set; } public int B { get; set; } public int C { get; set; } } public MainWindow() { InitializeComponent(); var list = new ObservableCollection<DataObject>(); list.Add(new DataObject() { A = 6, B = 7, C = 5 }); list.Add(new DataObject() { A = 5, B = 8, C = 4 }); list.Add(new DataObject() { A = 4, B = 3, C = 0 }); this.dataGrid1.ItemsSource = list; }
And the result will look like this: when editing the central cell:

Side Note: The WPF Grid class is for layout only. It does not support data editing support.
source share