4

How do i change the name of a column with C#? The datagrid is being populated with a Dictionary, and it defaults the title to be Value.

Cheers

6
  • Can you provide more information about your problem please. Post code if you can. Again, please refer Infragistics community forum for specific results. Sep 8, 2011 at 16:47
  • OK, so basically i have my datagrid with datasource set to the key values of a dictionary. But the column header of the grid is set to value. However i want to to be changed to something else. And it needs to be done in C#, but there doesnt see to be anything like datagrid.columnName = "foo"
    – User10
    Sep 8, 2011 at 16:54
  • The way we set header text of a infragistics grid's column is by accessing its fields collection.... like this... myXamDataGrid.FieldLayouts[0].Fields[0].Name = "Header1"... does this guide you in correct direction? Sep 8, 2011 at 17:22
  • This does exactly what i need, however, it seems to remove all the text from the fields after it? So after i attach it to the datasource (a dictionary) the title is correct but all the values have no text. (Still selectable mind you) Code is there fore like this... Processes.DataSource = Dict.Keys; Processes.FieldLayouts[0].Fields[0].Name = _envSel;
    – User10
    Sep 9, 2011 at 10:50
  • My bad! The setting should be myXamDataGrid.FieldLayouts[0].Fields[0].Label = "Header1" and the Name property must be the PropertyName from individual object represented by a Key.... e.g. if your dictionary Key is of type Employee class, then myXamDataGrid.FieldLayouts[0].Fields[0].Label = "Employee Name" and myXamDataGrid.FieldLayouts[0].Fields[0].Name = "EmpName"... let me know if this helps. Sep 9, 2011 at 10:59

1 Answer 1

8
foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn column in e.Layout.Bands[0].Columns)
{
    if(NamesEqual(column.Key, "ID"))
    {
        column.Header.Caption = "MyNewColumnName";
    }
}
2
  • tsells this is not Windows Infragistics but WPF. Sep 8, 2011 at 17:00
  • 1
    It's actually WinForms not Windows - but thanks anyway for the downvote.
    – tsells
    Sep 8, 2011 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.