I am trying to make a DataGrid with only one DataGridTextColumn. I do not want a header for this column, is there a flag or someway of making it invisible?
Thanks,
Evan
6 Answers, 1 is accepted
Currently there isn't a "HeaderVisibility" property for the DataGrid column types (see the properties list here).
However, you can achieve this by using a custom HeaderTemplate in conjunction with a HeaderStyle, try this for example:
<dataGrid:DataGridTextColumn PropertyName="Title"> <dataGrid:DataGridTextColumn.HeaderStyle> <dataGrid:DataGridColumnHeaderStyle BorderColor="Transparent" BorderThickness="0" BackgroundColor="Transparent" TextMargin="0" ... /> </dataGrid:DataGridTextColumn.HeaderStyle> <dataGrid:DataGridTextColumn.HeaderContentTemplate> <DataTemplate> <Grid Padding="0" Margin="0" /> </DataTemplate> </dataGrid:DataGridTextColumn.HeaderContentTemplate></dataGrid:DataGridTextColumn>Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Hello Michael,
All you need to do this is access to the column object (it doesn't have to be in XAML).
If you are creating the columns on the fly, then you can do this:
myColumn.HeaderTemplate = GenerateDataTemplateSeenInPreviousReply();
myColumn.HeaderStyle = new DataGridColumnHeaderStyle() { use properties in my last reply };If you are using AutoGenerateColumns=True, then this get a little trickier because there isn't an OnColumnGenerating event. You will need to decide when the time is right to iterate over all the columns and set the same values.
foreach(var column in MyDataGrid.Columns)
{
column.HeaderTemplate = ...;
column.HeaderStyle = ...;
}
Regards,
Lance | Manager - Technical Support
Progress Telerik
Hello Michael,
Not really. A few ideas I have that you could look into:
- Write a custom behavior that subscribes to the DataBindingComplete event (and access the column sin the behavior)
- Use EventToCommandBehavior with DatabindingComplete event and pass the DataGrid object to the view model (via CommandParameter)
- (unverified) Use OneWayToSource binding for the DataGrid Columns collection. You could then iterate over the Columns in the view model directly.
The bottom line is you need access to the Columns, so you can iterate over them to set their HeaderTemplate and HeaderStyle properties.
Regards,
Lance | Manager - Technical Support
Progress Telerik
