المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Linking the scroll bars of two controls



C# Programming
08-17-2011, 04:01 AM
Hi all,

I have two DataGridViews on my form with similar data in each. I'd like to view the same section of both DataGridViews at the same time. In other words, if the scroll bars in one DataGridView is scrolled, I want to set the scroll bars for the other one accordingly.

I found this article which explains how to set scroll bars (using Interop) but I'm either doing something wrong or it's just not working for DataGridViews:
How to change scrollbars position in a multiline textbox (http://www.codeproject.com/KB/cpp/scrollbar_position.aspx)[^ (http://www.codeproject.com/KB/cpp/scrollbar_position.aspx)]

Based on the referenced article, this is block of code I currently have in the Scroll() event handler for but it does nothing:
int orientation = 0;switch (e.ScrollOrientation){ case ScrollOrientation.HorizontalScroll: orientation = 0; break; case ScrollOrientation.VerticalScroll: orientation = 1; break;}SetScrollPos(dataGridView2.Handle, orientation, e.NewValue, true);SendMessage(dataGridView2.Handle, EM_LINESCROLL, 0, e.NewValue);
Could anyone help me out here please?