How create the Dynamic ROW and column in datagrid using WPF C#
Dear Team ,How create the Dynamic ROW and column in datagrid using WPF C#
Binding from database
http://stackoverflow.com/questions/20115742/wpf-dynamically-create-a-grid-with-specified-x-rows-and-y-columns-with-static
http://stackoverflow.com/questions/34009584/wpf-how-to-dynamically-create-a-grid-with-x-rows-and-y-columns-with-consecutive
private void CreateGraphicalDisplay(int rows,int columns,int row,int column)
{
ClearGraphicPanel();
for (int i = 1; i <= rows; i++)
{
StackPanel childstack = new StackPanel();
for (int j = 1; j <= columns; j++)
{
Image gage = new Image();
gage.Stretch = Stretch.Fill;
if (i == row && j == column)
{
gage.Source = new BitmapImage(new Uri(@Highlightedimage));
}
else
{
gage.Source = new BitmapImage(new Uri(@NormalImage));
}
gage.Width = 12;
gage.Height =12;
gage.HorizontalAlignment = HorizontalAlignment.Left;
gage.Margin = new Thickness(10, 1, 1, 1);
childstack.Children.Add(gage);
}
containerstack.Children.Add(childstack);
}
}
var datagrid = new DataGrid();
datagrid.Style = FindResource("ReadOnlyGridStyle") as Style;
datagrid.Columns.Add(new DataGridTextColumn()
{
Header = "Type",
Width = new DataGridLength(200),
FontSize = 12,
Binding = new Binding("Name")
});
datagrid.Columns.Add(new DataGridTemplateColumn()
{
Header = "Ingredients",
Width = new DataGridLength(1, DataGridLengthUnitType.Star),
CellTemplate = FindResource("IngredientsCellTemplate") as DataTemplate
});