|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Synchonised ListViewsI have 2 ListViews, one above the other, and I need to keep them horizontally synchronised. I managed to hide the bottom LV scrollbar (user is not supposed to scroll it) and to scroll it when user clicks on the scollbar or scrollbar arrows. However, the scrollbar does not move when the user keep the scrollbar thingy (I don't know the right word) and move it without releasing the mouse. And unfortunately, that's the easiest way of scrolling !!! Here is my code for the "chief listview" : ************************************************************* public class ScrollerListView : System.Windows.Forms.ListView { #region DLL IMPORT [DllImport("user32")] static extern IntPtr SendMessage(IntPtr Handle, Int32 msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", SetLastError=true) ] private static extern int GetScrollInfo(IntPtr hWnd, int n, ref ScrollInfoStruct lpScrollInfo); [DllImport("user32.dll")] static extern int SetScrollInfo(IntPtr hwnd, int fnBar, ref ScrollInfoStruct lpsi, bool fRedraw); private struct ScrollInfoStruct { public int cbSize; public int fMask; public int nMin; public int nMax; public int nPage; public int nPos; public int nTrackPos; } const int SB_LINELEFT = 0; const int SB_LINERIGHT = 1; const int SB_PAGELEFT = 2; //same value as SB_PAGEUP const int SB_PAGERIGHT = 3; //same value as SB_PAGEDOWN const int SB_THUMBPOSITION = 4; const int SB_THUMBTRACK = 5; const int SB_LEFT = 6; const int SB_RIGHT = 7; const int SB_ENDSCROLL = 8; const int WM_HSCROLL = 0x0114; const int SBS_HORZ = 0; const int SBS_VERT = 1; private const int SIF_RANGE = 0x1; private const int SIF_PAGE = 0x2; private const int SIF_POS = 0x4; private const int SIF_TRACKPOS = 0x10; private const int SIF_ALL = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS; #endregion protected ListView _attachedLV; public ScrollerListView(ListView attachedLV) : base() {_attachedLV = attachedLV; } protected override void WndProc(ref Message m) { if(m.Msg == WM_HSCROLL) { // Scroll other listview if (_attachedLV != null) { // Send scroll message to attached listview SendMessage(_attachedLV.Handle, m.Msg, m.WParam, m.LParam); Should move other scrollbar but does not work :( if (m.WParam.ToInt32() == SB_THUMBTRACK || m.WParam.ToInt32() {== SB_THUMBPOSITION) ScrollInfoStruct si = new ScrollInfoStruct(); si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; si.cbSize = Marshal.SizeOf(si); GetScrollInfo(this.Handle, SBS_HORZ, ref si); SetScrollInfo(_attachedLV.Handle, SBS_HORZ, ref si, true); } } } base.WndProc(ref m); } } ************************************************************* I hope someone will be able to help me on this one :( |
|||||||||||||||||||||||