Hi,
I used the following code to center align the cells in the grid.
<igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="HorizontalContentAlignment" Value="Center" /> </Style></igDP:XamDataGrid.Resources>
But this will align all the cells of the grid to Center. I want to align only one particular cell to Left and the remaining as it is (to Center). Con you tell me how to achieve this?
Thanks,
Varun
Varun,
Yes, this is one way to place a checkbox in a field. However, it is not necessary to create a style for the CellValuePresenter just to do that.
You can also set the EditAsType property to {x:Type sys:Boolean} (sys is a namespace for System; mscorlib) or set EditorType property to {x:Type idEditors:XamCheckEditor}.
By default, the grid would create a checkbox field if the value of that field is boolean. To center it, you should set the StackPanel's Horizontal/VerticalContentAlignment properties to center. I believe that should be enough. You also have CellContentAlignment property in the field settings.
Hope this helps.
Super show dude :-)
One more question...
How to center align the check box, which is one of the grid column.
I am using the following code to add a check box as columns to the grid. Is this the correct way to do or is there any other way to accomplish it?
<igDP:XamDataGrid Name="dgDet" Grid.Row="1" Grid.ColumnSpan="9" TabIndex="60" Width="Auto" GroupByAreaLocation="None" HorizontalAlignment="Center"> <igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="HorizontalContentAlignment" Value="Left" /> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" HighlightAlternateRecords="True" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="col1" Label="col1"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" LabelTextAlignment="Center"/> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="col2" Label="col2"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" LabelTextAlignment="Center"/> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="col3" Label="col3"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" LabelTextAlignment="Center"/> </igDP:Field.Settings> </igDP:Field> <igDP:UnboundField Name="col4"> <igDP:UnboundField.Settings> <igDP:FieldSettings> <igDP:FieldSettings.CellValuePresenterStyle> <Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <StackPanel> <StackPanel Orientation="Horizontal"> <CheckBox Name="chkSelect"></CheckBox> </StackPanel> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> </igDP:FieldSettings.CellValuePresenterStyle> </igDP:FieldSettings> </igDP:UnboundField.Settings> </igDP:UnboundField> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
Thanks
Then, you can create a style trigger (DataTrigger) and left align only the column Employee name:
<Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="HorizontalContentAlignment" Value="Center" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Field.Name, RelativeSource={RelativeSource Self}}" Value="EmployeeName">
<Setter Property="HorizontalContentAlignment" Value="Left" />
</DataTrigger>
</Style.Triggers> </Style>
Thanks for the reply Alex.
Consider i have grid with 3 columns, Employee ID, Employee Name and Employee Joining Date.
I want to right align The Employee ID Column cells, Left align the Employee Name column cells and the center align the Employee Joining Date column cells.
But the setter property what i mentioned is aligning all the cells to center.
Hello Varun,
This could be achievable with a Style trigger. Could you please provide more information on which cell you want to align left.
You can also take a look at this post by Andrew Smith using converters, so you can include your own custom logic in the converter.