We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to show horizontal scroll bar always on GridControl?

Thread ID:

Created:

Updated:

Platform:

Replies:

131434 Jul 9,2017 06:30 PM Jul 14,2017 12:05 AM Windows Forms 5
loading
Tags: GridControl
JeeNew
Asked On July 9, 2017 11:04 PM

I have a grid control with 2columns, column widths are 70px and 1000px respectively. But the width of the WinForms is just 900px, which is less than the width of the GridControl, hence trying to figure out how to show the horizontal scroll bar always.I have tried adding the below code into the constructor of the form and it is not working for me.            this.gridControl.HScroll = true;            this.gridControl.HScrollBehavior = GridScrollbarMode.Enabled;Is there any other property that I must enable to display the horizontal scroll bar?Thanks in advance!

Arulpriya Ramalingam [Syncfusion]
Replied On July 10, 2017 07:46 AM

Hi Jeevan,   
Thanks for using Syncfusion products.   
By default, the horizontal scroll bar will be added when the column width is more than the GridControl width. You can enable the horizontal scroll bar by enabling the HScroll and HScrollBehavior properties. We have created a simple sample as your scenario. Unfortunately, we are not able to reproduce the issue at our end. And we suspect that the issue occurs due to customization of your sample. Please ensure that whether the column width is higher than the GridControl width. Provide below details that will help us to provide you a better solution.   
  • A simple video or screenshot to reproduce the issue.
  • Sample code of setting the column width and form size or if possible modify the attached sample with issue replication which will help us to proceed further to provide you  a better solution as per your requirement.
 Regards,   
Arulpriya   


JeeNew
Replied On July 10, 2017 08:43 PM

Hi Arulpriya,

Setting the this.gridControl.HScrollPixel = true; fixed my issue. Thanks for the sample link.

I have another question -

 I have a very long column say 15000px long. Is there a way to have the header for this column fixed? So that even no matter what position the horizontal scroll bar is we can still see the header text.

Thanks in advance.

Jeevan


Arulpriya Ramalingam [Syncfusion]
Replied On July 12, 2017 01:33 PM

Hi Jeevan, 

Thanks for your update. 

By default, the HeaderText for a cell will be drawn at center of the cell. In order to fix the HeaderText at left of the cell when scrolling, the DrawCellDisplayText and HorizontalScroll events can be used. In DrawCellDisplayText event, RangeInfoToRectangle() method can be used to get the visible range of the cell and the string can draw manually using DrawString() method. Please make use of below code and sample, 

Code snippet 
 
//Event triggering 
this.gridControl1.HorizontalScroll += GridControl1_HorizontalScroll; 
 
//Event Cudtomization 
private void GridControl1_HorizontalScroll(object sender, ScrollEventArgs e) 
{ 
    this.gridControl1.InvalidateRange(GridRangeInfo.Row(0)); 
} 
 
//Event triggering 
this.gridControl1.DrawCellDisplayText += new GridDrawCellDisplayTextEventHandler(gridControl1_DrawCellDisplayText); 
 
//Event Customization 
void gridControl1_DrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e) 
{ 
    Rectangle rectangle = this.gridControl1.RangeInfoToRectangle(GridRangeInfo.Cell(e.RowIndex, e.ColIndex)); 
    Rectangle nextRectangle = this.gridControl1.RangeInfoToRectangle(GridRangeInfo.Cell(e.RowIndex, e.ColIndex + 1)); 
    Rectangle tableControlRectangle = this.gridControl1.ClientRectangle; 
    Rectangle textRect = e.TextRectangle; 
    if (e.RowIndex == 0 && 
            rectangle.X + rectangle.Width >= nextRectangle.X) 
    { 
        e.Graphics.DrawString(e.DisplayText, e.Style.GdipFont, new SolidBrush(e.Style.TextColor), (int)(rectangle.X), textRect.Y); 
        e.Cancel = true; 
    } 
} 
 
 

Regards, 
Arulpriya

JeeNew
Replied On July 13, 2017 06:36 PM

Hi ArulPriya,

Thanks a lot. The solution helped me.

Regards,

Jeevan


Arulpriya Ramalingam [Syncfusion]
Replied On July 14, 2017 12:05 AM

Hi Jeevan,   

We are glad to hear that the provided solution is resolved your scenario.   

Please let us know if you need further assistance.    
   
Regards,   
Arulpriya 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;