Hi,
I'm using a DataTable as the Datasource for a xamDataGrid. I have set the column captions for the columns directly on the datatable, but the grid is still using the column names as captions when it is displayed on screen. Is there a property / setting I'm missing that will make the grid use the captions instead of the names?
Thanks,Jacquers
Using the DefaultView and the event I suggested, you can try something like this:
void xamDataGrid1_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e)
{
FieldLayout f = (e.FieldLayout);
for (int i = 0; i<dt.Columns.Count;i++)
f.Fields[i].Label = dt.Columns[i].Caption;
}
Let me know if you have questions on this.
Alex.
Please attach a sample project with your application or the code you are using.
I have created a simple application myself with the following code and it works as expected. The caption is picked up as the display text (label) of the field.
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn() { ColumnName = "Column1", Caption = "Caption Col1" });
dt.Columns.Add(new DataColumn() { ColumnName = "Column2", Caption = "Caption Col2" });
dt.Columns.Add(new DataColumn() { ColumnName = "Column3", Caption = "Caption Col3" });
dt.Columns.Add(new DataColumn() { ColumnName = "Column4", Caption = "Caption Col4" });
dt.Rows.Add(1, 2, 3, 4);
xamDataGrid1.DataSource = dt.AsEnumerable();
I notice that if you set it as DefaultView (not as enumerable) the Caption property is not respected.
I'll have to take a look into that option, thank you for the suggestion.
Or maybe have a look at the source code of the grid if I'm feeling brave :)
In this case, I suppose it is best to use the FieldLayoutInitialized event of the XamDataGrid and set the corresponding caption < - > label.
Does this work in your scenario?
Thanks for your quick reply.
Ok, I understand that the name of the column in the grid has to be the same as the name of the column in the datatable and thats fine. I assumed that by setting the column caption in the datatable that this would automatically set the label property of the field to the same value in the grid?
Unfortunately I can't turn the Autogenerate columns off as I'm using databinding and the number of columns will be dynamic, so I can't harcode the values.