Click here to Skip to main content
15,908,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear people

I'm trying to scroll my FlowLayoutPanel UP or DOWN using click event button at run time but for some reason its not working. Here is the code.

C#
private void cmdButtonsUp_Click(object sender, EventArgs e)
        {
            int curItem = this.flowLayoutStockInButtonsPanel.VerticalScroll.Value;
            if (curItem > 0)
            {
                this.flowLayoutStockInButtonsPanel.VerticalScroll.Value = this.flowLayoutStockInButtonsPanel.VerticalScroll.LargeChange - 1;
            }
        }
        private void cmdButtonsDown_Click(object sender, EventArgs e)
        {
            int curItem = this.flowLayoutStockInButtonsPanel.VerticalScroll.Value;
            if (curItem < 0)
            {
                this.flowLayoutStockInButtonsPanel.VerticalScroll.Value = this.flowLayoutStockInButtonsPanel.VerticalScroll.LargeChange + 1;
            }
        }


Could someone please help me maybe I'm missing something on my code...

Thanks in advance


Lapeci
Posted

How your control knows that VerticalScroll properties are modified?
You need to trigger the layout update.

When the scrolling position is changed, add:

C#
flowLayoutStockInButtonsPanel.PerformLayout();


Thoroughly check up logics, calculation and constraints. In particular, use VerticalScroll.Minimum (you’re using 0, this is incorrect), VerticalScroll.Maximum, VerticalScroll.SmallChange.
 
Share this answer
 
v3
Comments
Espen Harlinn 28-Feb-11 15:09pm    
Nice and simple solution, my 5
Sergey Alexandrovich Kryukov 1-Mar-11 3:33am    
Thank you, Espen, that's all that involved.
--SA
victowork 11-Nov-14 2:20am    
Dear SAKryukov Please Help me
in which event I have to add flowLayoutStockInButtonsPanel.PerformLayout();
I always get 0 for this.flowLayoutStockInButtonsPanel.VerticalScroll.Value.

Please Help Its Very Urgent
Sergey Alexandrovich Kryukov 11-Nov-14 2:31am    
You already assigned scroll value to a scroll. After you do it, the missing piece is the call to PerformLayout.
—SA
victowork 11-Nov-14 3:09am    
how can i assign Scroll values my flowlayout panel consist of Usercontrols, Which will add dynamiccaly i have to buttons top and down. My code is just like this
private void BtnProdUp_Click(object sender, EventArgs e)
{
FlowProducts.PerformLayout();
int curItem = this.FlowProducts.VerticalScroll.Value;
if (curItem > 0)
{
this.FlowProducts.VerticalScroll.Value = this.FlowProducts.VerticalScroll.LargeChange - 1;
}
}

private void btnProdDown_Click(object sender, EventArgs e)
{
FlowProducts.PerformLayout();
int curItem = this.FlowProducts.VerticalScroll.Value;
if (curItem > 0)
{
this.FlowProducts.VerticalScroll.Value = this.FlowProducts.VerticalScroll.LargeChange + 1;
}
}
In both cases curItem would be <= And >=
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900