Hello, Dilshod,
You can iterate all columns in
RadGridView and set the GridViewColumn.
WrapText property to
true. Thus, the cell values will be wrapped. In addition, you can use the demonstrated approach in the following help article showing how to autosize the entire row by measuring the content. For this purpose it is necessary to create a custom
GridDataRowElement:
https://docs.telerik.com/devtools/winforms/gridview/rows/how-to/autosize-entire-row
As a result, you will have the desired minimum height for the headers in the
ColumnGroupsViewDefinition and autosize the data rows as it is illustrated in the screenshot.
Here is a complete code snippet:
public
RadForm1()
{
InitializeComponent();
this
.radGridView1.CreateRow += radGridView1_CreateRow;
foreach
(GridViewColumn col
in
this
.radGridView1.Columns)
{
col.WrapText =
true
;
}
}
private
void
radGridView1_CreateRow(
object
sender, GridViewCreateRowEventArgs e)
{
if
(e.RowType ==
typeof
(GridDataRowElement))
{
e.RowType =
typeof
(CustomRowElement);
}
}
private
void
RadForm1_Load(
object
sender, EventArgs e)
{
this
.customersTableAdapter.Fill(
this
.nwindDataSet.Customers);
ColumnGroupsViewDefinition view =
new
ColumnGroupsViewDefinition();
view.ColumnGroups.Add(
new
GridViewColumnGroup(
"Customer Contact"
));
view.ColumnGroups.Add(
new
GridViewColumnGroup(
"Details"
));
view.ColumnGroups[1].Groups.Add(
new
GridViewColumnGroup(
"Address"
));
view.ColumnGroups[1].Groups.Add(
new
GridViewColumnGroup(
"Contact"
));
view.ColumnGroups[0].Rows.Add(
new
GridViewColumnGroupRow());
view.ColumnGroups[0].Rows[0].ColumnNames.Add(
"CompanyName"
);
view.ColumnGroups[0].Rows[0].ColumnNames.Add(
"ContactName"
);
view.ColumnGroups[0].Rows[0].ColumnNames.Add(
"ContactTitle"
);
view.ColumnGroups[1].Groups[0].Rows.Add(
new
GridViewColumnGroupRow());
view.ColumnGroups[1].Groups[0].Rows[0].ColumnNames.Add(
"Address"
);
view.ColumnGroups[1].Groups[0].Rows[0].ColumnNames.Add(
"City"
);
view.ColumnGroups[1].Groups[0].Rows[0].ColumnNames.Add(
"Country"
);
view.ColumnGroups[1].Groups[1].Rows.Add(
new
GridViewColumnGroupRow());
view.ColumnGroups[1].Groups[1].Rows[0].ColumnNames.Add(
"Phone"
);
view.ColumnGroups[1].Groups[1].Rows[0].ColumnNames.Add(
"Fax"
);
view.ColumnGroups[1].RowSpan = 100;
view.ColumnGroups[1].Groups[0].RowSpan = 50;
view.ColumnGroups[0].Rows[0].MinHeight = 30;
radGridView1.ViewDefinition = view;
}
public
class
CustomRowElement : GridDataRowElement
{
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(GridDataRowElement);
}
}
protected
override
SizeF MeasureOverride(SizeF availableSize)
{
SizeF baseSize =
base
.MeasureOverride(availableSize);
CellElementProvider provider =
new
CellElementProvider(
this
.TableElement);
SizeF desiredSize = SizeF.Empty;
foreach
(GridViewColumn column
in
this
.ViewTemplate.Columns)
{
if
(!
this
.IsColumnVisible(column))
{
continue
;
}
GridDataCellElement cellElement = provider.GetElement(column,
this
)
as
GridDataCellElement;
this
.Children.Add(cellElement);
if
(cellElement !=
null
)
{
cellElement.Measure(
new
SizeF(column.Width,
float
.PositiveInfinity));
if
(desiredSize.Height < cellElement.DesiredSize.Height)
{
desiredSize.Height = cellElement.DesiredSize.Height;
}
}
cellElement.Detach();
this
.Children.Remove(cellElement);
}
SizeF elementSize =
this
.TableElement.RowScroller.ElementProvider.GetElementSize(
this
.RowInfo);
int
oldHeight = RowInfo.Height == -1 ? (
int
)elementSize.Height : RowInfo.Height;
this
.RowInfo.SuspendPropertyNotifications();
this
.RowInfo.Height = (
int
)desiredSize.Height;
this
.RowInfo.ResumePropertyNotifications();
if
(!
this
.RowInfo.IsPinned)
{
int
delta = RowInfo.Height - oldHeight;
TableElement.RowScroller.UpdateScrollRange(TableElement.RowScroller.Scrollbar.Maximum + delta,
false
);
}
baseSize.Height =
this
.RowInfo.Height;
return
baseSize;
}
private
bool
IsColumnVisible(GridViewColumn column)
{
return
column.IsVisible;
}
}
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik