This is a migrated thread and some comments may be shown as answers.

RadGridView horizontal scroll not working :(

14 Answers 977 Views
GridView
This is a migrated thread and some comments may be shown as answers.
chris petropoulos
Top achievements
Rank 1
chris petropoulos asked on 06 May 2010, 06:18 PM
Hi guys,

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

Sort by
0
Accepted
Jack
Telerik team
answered on 10 May 2010, 04:12 PM
Hi chris petropoulos,

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.
0
chris petropoulos
Top achievements
Rank 1
answered on 25 May 2010, 05:07 AM
Thanks for the quick answer. it worked perfectly :-)
0
Phi
Top achievements
Rank 1
answered on 31 Oct 2010, 12:09 PM
What if I want the effect of the Fill mode and also have the horizontal scroll bar as well? How would you suggest I would go about doing that without using a scrollable panel or some other kind of control?

Thanks,

Phi
0
Nikolay
Telerik team
answered on 12 Nov 2010, 10:13 AM
Hello 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
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
0
Gabriele
Top achievements
Rank 1
answered on 03 Dec 2010, 03:36 PM
I had the same issue and I resolved this way using the SizeChanged event:

 

 

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;
        }
    }
}

 

0
Jack
Telerik team
answered on 08 Dec 2010, 03:26 PM
Gabriele, thank you for sharing your solution with the community.

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
Get started with RadControls for WinForms with numerous videos and detailed documentation.
0
Baris
Top achievements
Rank 2
answered on 02 Aug 2011, 12:51 PM
I guess I have the same scenario with Gabriele but his solution is not working as it should be.

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
0
Svett
Telerik team
answered on 05 Aug 2011, 06:59 AM
Hi Baris,

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
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
Erwin
Top achievements
Rank 1
answered on 09 Nov 2011, 05:47 PM
Hello Svett,

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
0
Svett
Telerik team
answered on 14 Nov 2011, 01:25 PM
Hello Dries Van Hansewijck,

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.

0
Praveena
Top achievements
Rank 1
answered on 22 Nov 2011, 09:26 AM
Hi All,

        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
0
Svett
Telerik team
answered on 24 Nov 2011, 04:50 PM
Hi 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
Regards,
Svett
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

0
Brennan
Top achievements
Rank 1
answered on 25 Nov 2011, 11:28 PM
Further to Svett's post, I just wanted to give people an enhanced way to resize columns that adds support for Grid's which have column groupings:

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!
0
Svett
Telerik team
answered on 30 Nov 2011, 11:37 AM
Hi Brennan,

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.

Tags
GridView
Asked by
chris petropoulos
Top achievements
Rank 1
Answers by
Jack
Telerik team
chris petropoulos
Top achievements
Rank 1
Phi
Top achievements
Rank 1
Nikolay
Telerik team
Gabriele
Top achievements
Rank 1
Baris
Top achievements
Rank 2
Svett
Telerik team
Erwin
Top achievements
Rank 1
Praveena
Top achievements
Rank 1
Brennan
Top achievements
Rank 1
Share this question
or