Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DataGridView ScrollEventArgs Question
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01404628
Message ID:
01405261
Vues:
36
>>>>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.
>
>ScrollBar.Value is (again as per docs) the position of the drag-able thumb - not the position of the content. Assuming that the left edge of your control is aligned with the grid then all that should be required in the event handler is:
Headers.Left = Grid.Left - e.NewValue;
OHHH.. Well that's my mistake. I misunderstood. Silly me

Thanks
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform