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. Image for the cookie policy date
close icon

Scroll Jump

I''m sure this is a simple answer, but I am unable to find the solution. In C# I am using a DataBoundGrid that has two columns. The first column is small in width and the second is very long. When the user clicks the second cell, there is an underlying event that moves the Horizontal Scrollbar over to the beginning of that second column. This event is hiding my first column from view, requiring the user to scroll back. Does anyone know how to prevent this behaviour, so the only scrolling being done is being performed by the user.

9 Replies

AD Administrator Syncfusion Team October 25, 2004 05:48 PM UTC

If the second column is not fully visible, then grid will scroll to try to make it visible. This sounds like what you are describing. There is no property setting that will avoid this. You could try to enlarge your grid so both the first and second columns are fully visible. Or, if you do not want to do this, you can handle the grid.LeftColChanging event, and cancel it to avoid the scrolling.


AD Administrator Syncfusion Team October 26, 2004 09:45 AM UTC

Yes Clay, that is the behaviour I was refering to. By using the LeftColChanging event the user is no longer able to scroll horizontally. I think I am going to create a third column containing both columns and hide the first two. This should give me the behaviour I want. Thank for your time.


AD Administrator Syncfusion Team October 26, 2004 10:45 AM UTC

gotta jump in here, have you tried this.gridDataBoundGrid1.HScrollPixel = true;


AD Administrator Syncfusion Team October 26, 2004 10:59 AM UTC

and dont forget this.gridDataBoundGrid1.HorizontalThumbTrack = true;


AD Administrator Syncfusion Team October 27, 2004 12:03 PM UTC

HScrollPixel was exactly what I was looking for! Thanks! Works perfect!


NE Nethar September 20, 2007 11:00 AM UTC

I am using this HScrollPixel property so it is possible to drag the scrollbar and scroll whereever you want. When I just click to scrollbar to left or right, it jumps to next column in my case, not by pixels. OK, it's fine.
The problem is if I have column which is for example twice as wide as the client area of my grid. Let's say I scroll to the right end of my column and trying to resize it little bit. After resizing it scrolls to the left border of that column everytime, I would like it to stay where it is. What can be source of this problem? Thanks!


BP Bhuvaneswari P Syncfusion Team September 27, 2007 01:48 PM UTC

Hi Nethar,

Yes, this can be possible by cancelling the HScrollPixel event while resizing the column. This will cancel the scrolling, so that it will not move to column left. Please refer the below code snippet do so.

//Subscribe Event
this.gridDataBoundGrid1.ResizingColumns += new Syncfusion.Windows.Forms.Grid.GridResizingColumnsEventHandler(gridDataBoundGrid1_ResizingColumns);

//event
void gridDataBoundGrid1_ResizingColumns(object sender, Syncfusion.Windows.Forms.Grid.GridResizingColumnsEventArgs e)
{

this.gridDataBoundGrid1.HScrollPixelPosChanging +=new GridScrollPositionChangingEventHandler(gridDataBoundGrid1_HScrollPixelPosChanging);

}

void gridDataBoundGrid1_HScrollPixelPosChanging(object sender, GridScrollPositionChangingEventArgs e)
{
e.Cancel = true;
}
Please download the sample from the below link.
http://websamples.syncfusion.com/samples/Grid.Windows/F20776/main.htm

Please let me know if this help you.

Best Regards,
Bhuvana


NE Nethar October 3, 2007 08:14 AM UTC

Thank you, I have tried it.

There was a problem, that after first resize, it was not possible to scroll with horizontal scrollbar anymore (probably because HScrollPixelPosChanging was canceled in event handler). I noticed same behaviour in your example.
So for now I made this change in my code:
void hGrid_HScrollPixelPosChanging(...)
{
if (m_bCancelScroll) {
e->Cancel = true;
m_bCancelScroll = false;
}
}

and in hGrid_ResizingColumns I added
m_bCancelScroll = true;

so now scrolling is canceled only if comes from ResizingColumns and not for example from moving the scrollbar. Is it correct?

But there is one more scrolling I want to cancel, I will try to explain: I have 3 columns - first is wider than grid width, second and third are small. I scroll to right side (see my screenshot). Now when I make first column smaller (resize it) it is not possible for scrollbar stay on the same position (because whole width of grid is reduced), so it jumps to the start of first column again. Is it possible for scrollbar to stay on the right edge?
Hope you understand what I mean,
Thank you!


grid01.zip


BP Bhuvaneswari P Syncfusion Team October 5, 2007 04:06 AM UTC

Hi Nethar,

Thanks for the update.

Yes, It is possible for scrollbar to stay on the right edge, when you make first column smaller by using the below code snippet.

void gridDataBoundGrid1_ScrollControlMouseMove(object sender, Syncfusion.Windows.Forms.CancelMouseEventArgs e)
{
flag = false;
this.gridDataBoundGrid1.Refresh();
}

void gridDataBoundGrid1_ResizingColumns(object sender, Syncfusion.Windows.Forms.Grid.GridResizingColumnsEventArgs e)
{
flag = true;
this.gridDataBoundGrid1.HScrollPixelPosChanging +=new GridScrollPositionChangingEventHandler(gridDataBoundGrid1_HScrollPixelPosChanging);
this.gridDataBoundGrid1.Refresh();

}
void gridDataBoundGrid1_HScrollPixelPosChanging(object sender, GridScrollPositionChangingEventArgs e)
{
if(flag ==true)
e.Cancel = true;

}

Please download the modified sample from the below link:
http://websamples.syncfusion.com//samples/Grid.Windows/F20776_2/main.htm

Please let me know if you have any other queries.

Best Regards,
Bhuvana


Loader.
Live Chat Icon For mobile
Up arrow icon