Hi,
To show records in horizontal, i set the Orientation property off the GridViewSettings .And i also need to adjust the size of all cells' width to fit within its boundaries. But use by setting a FieldLayoutSettings object’s AutoFitMode property , autosizing the Height when the Orientation is Horizontal. Could anyone please help? Thanks.
Hello Jing,
The AutoFitMode property, is used to define whether fields are resized to always fill the available area of the XamDataGrid and since the orientation of the gird is set to Horizontal, the AutoFitMode would be applied on the height of the grid, extending the fields to fit in the total height of the grid. This is because only autosizing of the logical column extent is supported. For example, the Width when the Orientation is Vertical and the Height when the Orientation is Horizontal.
The width of the fields could still be modified from FieldSetting with the following properties - CellWidth, CellMaxWidth and CellMinWidth.
Moreover, a text wrapping could be applied to fit the cells content to the width of the field. Since the gird has Horizontal orientation the height property needs to be modified with a value that would fit the contents of the cell. This could be achieved by styling the XamTextEditor like this:
<igWPF:XamDataGrid.Resources>
<Style TargetType="{x:Type igEditors:XamTextEditor}">
<Setter Property="TextWrapping" Value="Wrap"/>
<Setter Property="Height" Value="40"/>
</Style>
</igWPF:XamDataGrid.Resources>
Please let me know if you have any questions.
Regards, Ivan Kitanov
I want to make Width property of Field to the auto size, when using horizontal orientation of XamDataGrid ,like AutoFitMode works on height.
As I mentioned in my previous response The AutoFitMode property, is used to define whether fields are resized to always fill the available area of the XamDataGrid, which would make the grid occupy all the available height, however this would not make the width of the cells to fit the content of the cells.
The logical width of a column is always a fixed value and is never sized based on content, however with TextWrapping it could be manipulated based on the Height property. To do this you could define dynamic resource and use its value as the value of the Height, while targeting the XamTextEditor. Then an event handler could be used to change this value based on a certain condition.
To add dynamic resource the path to system needs to be added:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Then the resource should be created like this:
<Window.Resources>
<sys:Double x:Key="WrapHeight">40</sys:Double>
</Window.Resources>
After that the only change needed is to change the value of the Height to the dynamic resource, which could be done like this:
<igWPF:XamDataGrid Name="xamDataGrid1" >
<Setter Property="Height" Value="{DynamicResource WrapHeight}"/>
To change the Height, when the user changes the text inside a cell that has XamTextEditor as its editor, what I can suggest you is using the CellUpdated event. Inside it a condition should be established to determine the Height of the XamTextEditor, an example of this could be the length of the cell value. Below I am pasting a code snipped that increases the value of the dynamic resource for the Height when the text of the cells contains more than 50 characters:
if (this.xamDataGrid1.ActiveCell != null)
{
if (this.xamDataGrid1.ActiveCell.Value.ToString().Length > 50) this.Resources["WrapHeight"] = 100.0;
}