You must Sign In to post a response.
  • Category: WPF

    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
  • #768773
    Hai Hemz,
    To create the dynamic rows and columns, you can use the listView and then use the list object as observable and then add them to the list view.
    You can also see some other work around in the below links:

    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

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #768776
    checkout below code it may help you more in order to create dynamic rows and columns to datagrid

    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);
    }
    }

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #768798
    You can use given code snippet to create new DataGrids in your code-behind
     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
    });


  • Sign In to post your comments