User Specify total number of columns at runtime. According to runtime input the colunm should be created dynamically. Here i'm not able to add new row.
- <DataGrid x:name="dataGrid"/>
- DataGridTextColumn so = new DataGridTextColumn();
- so.Header = "S.No";
- dataGrid.Columns.Add(so);
- DataGridTextColumn name= new DataGridTextColumn();
- name.Header = " Name";
- dataGrid.Columns.Add(name);
- DataGridColumn age= new DataGridTextColumn();
- age.Header = "Age";
- dataGrid.Columns.Add(age);
- for (int i = 1; i <= (new Random()).Next(1, 50); i++)
- {
- DataGridComboBoxColumn ss = new DataGridComboBoxColumn();
- ss.Header = i;
- List<string> list = new List<string>();
- list.Add("Item 1");
- list.Add("Item 2");
- ss.ItemsSource = list;
- ss.Width = 50;
- ss.EditingElementStyle = style;
- dataGrid.Columns.Add(ss);
- }
Replies
Know the answer? Post it — somebody with the same question will find it here.