1

I am searching a simple method through which i can bind my DataGridColumn with a Datatable columns on the fly. I should also be able to define the width of each column.

Example :-

If My program generates 5 columns in a datatable, so the DataGrid should be able to dispaly 5 columns with each having different column width.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Megatron
  • 93
  • 1
  • 2
  • 8

1 Answers1

1

I figured out the answer:

dtgrdAtlas.Columns.Add(
                        new DataGridTextColumn
                        {
                            Header = dc.ColumnName,
                            Width = 100,
                            IsReadOnly = true,
                            Binding = new Binding(string.Format("[{0}]", dc.ColumnName))
                        });

dtgrdAtlas = DataGrid

dc = DataColumn belonging to a data table

It does the binding too!

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Megatron
  • 93
  • 1
  • 2
  • 8