Donate

Adding An Item to WPF Datagrid (C#)

Hello!

VB.NET Version: Adding An Item to WPF Datagrid (VB.NET)

Here's the C# version of how to add an item manually to a WPF DataGrid.
DataGridTextColumn c1 = new DataGridTextColumn();  
c1.Header = "Test";  
c1.Binding = new Binding("test");  
 c1.Width = 473;  
dataGrid.Columns.Add(c1);  
dataGrid.Items.Add(new Names() {test="just testing"});
Class property:
public string test { get; set; }  
XAML code:
 <DataGrid AutoGenerateColumns="False" Height="289" HorizontalAlignment="Left" Margin="10,10,0,0" Name="dataGrid"   
          VerticalAlignment="Top" Width="481" Grid.ColumnSpan="2" ItemsSource="{Binding }">  
     </DataGrid>  

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input