RadGridView horizontal scroll not working :(

15 posts, 1 answers
  1. chris petropoulos
    chris petropoulos avatar
    5 posts
    Member since:
    Mar 2010

    Posted 06 May 2010 Link to this post

    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.

  2. Answer
    Jack
    Admin
    Jack avatar
    2333 posts

    Posted 10 May 2010 Link to this post

    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.
  3. chris petropoulos
    chris petropoulos avatar
    5 posts
    Member since:
    Mar 2010

    Posted 25 May 2010 Link to this post

    Thanks for the quick answer. it worked perfectly :-)
  4. Phi
    Phi avatar
    47 posts
    Member since:
    Dec 2008

    Posted 31 Oct 2010 Link to this post

    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
  5. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 12 Nov 2010 Link to this post

    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
  6. Gabriele
    Gabriele avatar
    14 posts
    Member since:
    Oct 2010

    Posted 03 Dec 2010 Link to this post

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

     

  7. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 08 Dec 2010 Link to this post

    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.
  8. Baris
    Baris avatar
    5 posts
    Member since:
    May 2011

    Posted 02 Aug 2011 Link to this post

    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
  9. Svett
    Admin
    Svett avatar
    728 posts

    Posted 05 Aug 2011 Link to this post

    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 >>
  10. Erwin
    Erwin avatar
    5 posts
    Member since:
    Oct 2009

    Posted 09 Nov 2011 Link to this post

    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
  11. Svett
    Admin
    Svett avatar
    728 posts

    Posted 14 Nov 2011 Link to this post

    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.

  12. Praveena
    Praveena avatar
    3 posts
    Member since:
    Feb 2011

    Posted 22 Nov 2011 Link to this post

    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
  13. Svett
    Admin
    Svett avatar
    728 posts

    Posted 24 Nov 2011 Link to this post

    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.

  14. Brennan
    Brennan avatar
    39 posts
    Member since:
    Sep 2010

    Posted 25 Nov 2011 Link to this post

    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!
  15. Svett
    Admin
    Svett avatar
    728 posts

    Posted 30 Nov 2011 Link to this post

    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.

Back to Top