Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataGridView ScrollEventArgs Question
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01404628
Message ID:
01405098
Views:
34
>>I have some custom headers above a data grid view. When the user scrolls the data grid view left or right, I want to move the headers along with it, except I can't seem to figure it out
>>
>>Here's my code:
>>
>>
>>private void dgvInventory_Scroll(object sender, ScrollEventArgs e)
>>{
>>    if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
>>    {
>>        int iChangeAmount = 0;
>>        int iHeaderLeft = 0;
>>
>>        switch (e.Type)
>>        {
>>            case ScrollEventType.SmallIncrement:
>>                iChangeAmount = 98;
>>                break;
>>
>>            case ScrollEventType.SmallDecrement:
>>                iChangeAmount = 98;
>>                break;
>>
>>            case ScrollEventType.LargeDecrement:
>>                iChangeAmount = 910;
>>                break;
>>
>>            case ScrollEventType.LargeIncrement:
>>                iChangeAmount = 910;
>>                break;
>>        }
>>
>>
>>        if (e.NewValue > 0) // Right thumb clicked
>>        {
>>            // Move the headers to the left
>>            iHeaderLeft = iChangeAmount * -1;
>>        }
>>
>>        if (e.OldValue > 0)
>>        {
>>            // Move the headers to the right
>>            iHeaderLeft = iChangeAmount;
>>        }
>>
>>        Headers.Left = Headers.Left + iHeaderLeft;
>>
>>// Debug labels
>>label1.Text = e.NewValue.ToString();
>>label2.Text = e.OldValue.ToString();
>>label3.Text = iHeaderLeft.ToString();
>>    }
>>}
>>
>>The first time I click the right thumb e.OldValue is 0 and e.NewValue is 98. Where is this 98 coming from? What determines this?
>>Seems to me it would alot less confusing if the control has a VisiblePortionLeft property. This would always be zero or less when horizontal scrolling.
>>
>>At any rate, my code isn't working. Anyone have an example of how to do scrolling. Google's results are too ambigous.
>>
>>Thanks
>
>Did you read the ScrollEventArgs documentation?
>.OldValue is the previous ScrollBar.Value and .NewValue is the current ScrollBar.Value. The change is the difference between the two.
>Don't think the ScrollEventType is relevant.

I still don't get it. If I click the right thumb, the grid scrolls to the left, and e.NewValue is 88, which is really -88 since the grid is off the left side of the view.

I don't understand how to compute where the left side of my header should be.
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform