Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have two ListBoxAdv1 and ListBoxAdv2 and i want sync them scroll i used this code and just shown scrolled up or down but didn't update screen and items in another ListBoxAdv

what should i do? please help

What I have tried:

i try this:
private void listBoxAdv1_Scroll(object sender, ScrollEventArgs e)
{
       listBoxAdv2.VScrollBar.Value = listBoxAdv1.VScrollBar.Value;
}
private void listBoxAdv2_Scroll(object sender, ScrollEventArgs e)
{
      listBoxAdv1.VScrollBar.Value = listBoxAdv2.VScrollBar.Value;
}


and this:

private void listBoxAdv1_Scroll(object sender, ScrollEventArgs e)
{
               listBoxAdv2.Focus();
                   ScrollEventArgs scrollEventArgs = new ScrollEventArgs(ScrollEventType.SmallIncrement, e.OldValue, e.NewValue, ScrollOrientation.VerticalScroll);
                  listBoxAdv2_Scroll(listBoxAdv2, scrollEventArgs);
}
private void listBoxAdv2_Scroll(object sender, ScrollEventArgs e)
{
     
}
Posted
Updated 28-May-18 21:08pm

1 solution

thanks for many response!
i find solution:

bool Scrolling = true;
       private void listBoxAdv1_Scroll(object sender, ScrollEventArgs e)
       {
           if (Scrolling == true)
           {
               Scrolling = false;
               listBoxAdv2.BeginUpdate();
               listBoxAdv2.AutoScrollPosition = new Point(listBoxAdv1.AutoScrollPosition.X, listBoxAdv1.AutoScrollPosition.Y);
               listBoxAdv2_Scroll(sender, e);
               listBoxAdv2.EndUpdate();
               Scrolling = true;
           }
       }

       private void listBoxAdv2_Scroll(object sender, ScrollEventArgs e)
       {
           if (Scrolling == true)
           {
               Scrolling = false;
               listBoxAdv1.BeginUpdate();
               listBoxAdv1.AutoScrollPosition = new Point(listBoxAdv2.AutoScrollPosition.X, listBoxAdv2.AutoScrollPosition.Y);
               listBoxAdv1_Scroll(sender, e);
               listBoxAdv1.EndUpdate();
               Scrolling = true;
           }
       }
 
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