8 Answers, 1 is accepted
Hello Sergey,
There is no direct method for resizing columns individually, but the control provides APIs that can be useful in your case. The ColumnWidth property of RadVirtualGrid allows you to set an unified size for all columns. Also, you can use the FitColumnWidthToContent method which resizes the column's width to the size of the largest cell. Additionally, there is an HeaderSizeNeeded event which fires when the control is measured and arranged. In the event handler, you can set the size of the header. For example:
public MainWindow()
{
InitializeComponent();
this.virtualGrid.HeaderSizeNeeded += RadVirtualGrid_HeaderSizeNeeded;
}
private void OnButtonClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
SetColumnWidth(1, 20);
}
private double columnWidthCache = -1;
private double columnIndexCache = -1;
private void SetColumnWidth(int columnIndex, double width)
{
this.columnIndexCache = columnIndex;
this.columnWidthCache = width;
var widthCache = this.virtualGrid.ColumnWidth;
this.virtualGrid.ColumnWidth = 0;
this.virtualGrid.ColumnWidth = widthCache;
}
private void RadVirtualGrid_HeaderSizeNeeded(object sender, Telerik.Windows.Controls.VirtualGrid.HeaderSizeEventArgs e)
{
if (e.Index == this.columnIndexCache)
{
e.Size= this.columnWidthCache;
}
}
I hope this information helps.
Regards,
Martin Ivanov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hello Martin,
Thanks for the example, this looks like what I need.
Hello Sergey,
Currently there isn't an option to obtain the actual size of the header. That said, if you are modifying the sizes in code, you can keep them in a variable (for example a dictionary of column index - size). Additionally, you can use the HeaderOrientation property of the event arguments to determine whether the event is fired for a row or column header. That said, currently it is only fired for column headers.
On a side note, we have logged a new feature request for introducing an api for resizing the columns in code: VirtualGrid: Introduce API for programatically resizing the columns. You can follow the item in order to get notified for any updates. I have also added some telerik points to your account as a thank you for bringing this to our attention.
Regards,
Vladimir Stoyanov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hello Vladimir,
At the moment, I still save the dimensions, but the user can change them and this data is already lost without the ability to get the size programmatically. With regards to HeaderOrientation, it was meant that the event is called 2 times with the HeaderOrientation Horizontal and 0 column index. And it is not possible to understand whether the column is mine or the system one for the row headers.
That is, my task is to save and load user settings, and at the moment this is impossible.
Hello Sergey,
Thank you for the update.
I am afraid that the RadVirtualGrid does not support obtaining the actual size of the columns after the user has resized them. This is due to the fact that the control has very few actual visual elements in order to improve its performance. However, this comes at the cost of lacking certain features.
If obtaining the size of the columns at runtime is important for your scenario, I can suggest switching to the RadGridView, which is the feature-rich alternative of the RadVirtualGrid.
On a side note, the HeaderSizeNeeded event is fired for the user columns first and for the row headers last. With this in mind, the first time that the index is 0, the event is fired for the first column and the second time, it is fired for the row indicator column.
Regards,
Vladimir Stoyanov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hello Vladimir,
Thanks for the info.
Regarding RadGridView, I am aware, VirtualGrid was chosen because performance is required, however, some functions are still missing, but there is no way to sacrifice performance to get them.