Im only just starting to use Rad controls for winforms, and i know i have such a stupid question. But how do i get a horizontal scroll bar to work with the RadGridView. Il explain my problem below:
Eg - i have 10 columns in the grid, and havent actually set any specific widths on them, and call
radGridView1.MasterGridViewTemplate.BestFitColumns();
Now when i click one the columns to make it autosize to fit its contents, eg a column that has a long sentence in it, i expect to see a horizontal scroll bar so that i can stil scroll to view the other columns. But unfortunately the scroll bar never shows up :( Even though HorizontalScollState = AutoHide. All i simply want is for a scroll bar to show up when there are too many columns.
I must be missing something for sure! Do i need to set specific widths on columns, so that the scroll bar comes up and works?
Thanks for any suggestions.
Chris.
14 Answers, 1 is accepted
RadGridView's horizontal scrollbar will always be hidden when AutoSizeColumnsMode is set to Fill. You should set this property go None to see the scrollbar:
this
.radGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None;
I hope this helps. If the issue continues to appear, please send me your project and I will try to locate the issue.
Regards,
Jack
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Thanks,
Phi
The purpose of the Fill mode is to make the columns fit in the estate area of the RadGridView control. That said, no horizontal scrollbar is needed to scroll the columns.
If you want to have columns that exceed the estate area of the grid control, you should set the AutoSizeColumnsMode to Node. This will allow you to use the horizontal scrollbar.
Best wishes,
Nikolay
the Telerik team
void HistoryGrid_SizeChanged(object sender, System.EventArgs e)
{
if (HistoryGrid.MasterTemplate.Columns.Count > 0)
{
int columnsWidth = 0;
for (int index = 0; index < HistoryGrid.MasterTemplate.Columns.Count; index++)
{
if (HistoryGrid.Columns[index].IsVisible)
{
columnsWidth += HistoryGrid.Columns[index].Width;
}
}
int gridWidth = HistoryGrid.Width;
if (columnsWidth > gridWidth)
{
this.HistoryGrid.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None;
}
else
{
this.HistoryGrid.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
}
}
}
Phi, you can call the BestFitColumns method to adjust the width for every column. When AutoSizeColumnsMode is set to None and there is not enough space to show all columns, this will show the horizontal scrollbar.
In future, we plan to extend the column sizing modes supported by RadGridView and we want to consider your scenario. Please give us more details on what exactly you want to achieve.
I am looking forward to your reply.
All the best,
Jack
the Telerik team
I have a RadGridView. I want it to fill the horizontal space AND I want to have horizontal scroll bar if the content inside one of the coloumns is wider than its coloumn. Gabriele's code is working after some point when narrowing the screen, but till that point the content (my textbox string) is getting shorter with a (...) in the end. When it gets like 60% width, the scroll appears.
It's always set to BestFitColoumns. Using Q2 2011
You can perform best fit columns and if the total width of the columns is less than the grid's width, increase their size manually. You use the following code snippet below:
this
.radGridView1.BestFitColumns();
int
width =
this
.radGridView1.TableElement.GroupIndent;
int
visibleColumnsCount = 0;
foreach
(GridViewDataColumn column
in
this
.radGridView1.Columns)
{
if
(column.IsVisible)
{
visibleColumnsCount++;
width += column.Width;
}
}
int
offset =
this
.radGridView1.Width - width;
if
(offset > 0)
{
int
delta = offset / visibleColumnsCount;
foreach
(GridViewDataColumn column
in
this
.radGridView1.Columns)
{
if
(column.IsVisible)
{
column.Width += delta;
}
}
}
I hope this helps. Greetings,
Svett
the Telerik team
I have come across a similar situation and used your code snippet.
I just wanted to comment that I used the OnLayout (or subscribe to layout) method on a UserControl to execute the functionality. This way, columns are automatically enlarged whenever there is more space available (eg after enlarging the Form).
Dries
Thank you for sharing your approach with us. It is a good alternative.
Greetings,Svett
the Telerik team
Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.
I want to trap the scroll event in radgridview. For vertical scroll.. Please let me know how it can be achieved. I coded in scroll event of the grid.However that event is not getting fired at all. Actually i have 3 radgridviews. One below the other. As i scroll any of the radgrid, the other 2 radgrids should also get scrolled to that positon. To accomplish this as far as i know i can use the below code
dg2.TableElement.VScrollBar.Value = dg1.TableElement.VScrollBar.Value;
dg3.TableElement.VScrollBar.Value = dg1.TableElement.VScrollBar.Value;
However not sure in which event i have to write this code. Please help at the earliest
Thanks and Regards,
Praveena
You can use the RowScroller's event to handle the desired behavior:
C#
this
.radGridView1.TableElement.RowScroller.ScrollerUpdated +=
this
.OnRowScrollerUpdated;
private
void
OnRowScrollerUpdated(
object
sender, EventArgs e)
{
// TO DO: Your synchronization logic here
}
VB.NET
AddHandler
Me
.grdMain.TableElement.RowScroller.ScrollerUpdated,
AddressOf
OnRowScrollerUpdated
Private
Sub
OnRowScrollerUpdated(
ByVal
sender
As
System.
Object
,
ByVal
e
As
EventArgs)
End
Sub
Svett
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
Public
Shared
Sub
ResizeTelerikGrid(
ByVal
grid
As
RadGridView)
grid.BestFitColumns()
Dim
width
As
Integer
= (grid.TableElement.GroupIndent * grid.GroupDescriptors.Count) + grid.TableElement.GroupIndent
Dim
visibleColumnsCount
As
Integer
= 0
For
Each
column
As
GridViewDataColumn
In
grid.Columns
If
column.IsVisible
AndAlso
Not
column.IsGrouped
Then
visibleColumnsCount += 1
width += column.Width
End
If
Next
Dim
offset
As
Integer
= grid.Width - width
If
offset > 0
Then
Dim
delta
As
Integer
= offset \ visibleColumnsCount
For
Each
column
As
GridViewDataColumn
In
grid.Columns
If
column.IsVisible
Then
column.Width += delta
End
If
Next
End
If
End
Sub
Cheers!
Thank you for your clarification and community effort.
Best wishes,Svett
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.