Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically Scrolling a Listview

Status
Not open for further replies.

SlantyOD

Programmer
Jun 11, 2002
22
0
0
CA
Hi All,

I'm trying to tie two ListViews together so that when the user scrolls one, the other stays 'in sync'. Since there are no OnScroll events, and the scroll bar position is unavailable, I've been forced to create my own ListView class and override WndProc. In this I've caught all instances of WH_VScroll and WH_HScroll, and then I can pass this info onto the second ListView by using the User32.dll method SendMessage. This all works beautifully if the user clicks on teh arrow buttons, but doesn't work if the user decides to click and drag the bar along the scrollbar. I've determined that the problem is in handling the SB_ThumbTrack and SB_ThumbPosition values. But beyond that I'm stumped. I don't suppose anybody knows anything about this? I've posted my Class below, I'm just setting the Associated ListView manually when I create the class for now. I've edited out somestuff, but left in the code for determining the HIWORD and LOWORD values which may or may not be important. I'm pretty much way in over my head on this one =).

CHeers,
SlantyOD

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;


namespace myNameSpace
{
public class MyListView : System.Windows.Forms.ListView
{
public ListView AssociatedListView;
private System.ComponentModel.Container components = null;
[DllImport("User32.dll")]
private static extern bool SendMessage(IntPtr hwnd, UInt32 msg, UInt32 wParam, UInt32 lParam);

public MyListView()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
{
components.Dispose();
}
base.Dispose( disposing );
}


private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}


private const int WM_HSCROLL = 0x114;
private const int WM_VSCROLL = 0x115;
protected override void WndProc(ref Message msg)
{

// Look for the WM_VSCROLL or the WM_HSCROLL messages.
if (msg.Msg == WM_HSCROLL)
{
int myInt = msg.WParam.ToInt32();
int IntLow = myInt & 0xffff;
long IntHigh = ((long)myInt & 0xffff0000) >> 16;
SendMessage(this.AssociatedListView.Handle, (int)WM_HSCROLL, (uint)msg.WParam.ToInt64(), (uint)msg.LParam.ToInt64());
}
// Pass message to default handler.
base.WndProc(ref msg);
}
}
}
 
The VScrollBar bar is already provided by the ListView control.
I think you have to add the HScrollBar control in the container of your ListView class and overload some functions like Resize()...
The both VScrollBar and HScrollBar controls rise OnScroll() event.
-obislavu-
 
I don't suppose you have a code example do you? I don't seem to be able to grab the HScrollBar or VScrollBar through ListView.Controls even though there's enough data in the ListView that both are visible. If I could get a hold of them that would be great.
 
Just an addition here. When I override the WndProc and use SendMessage to send the info along, using Spy++ I can see that the SB_ThumbPosition and the SB_ThumbTrack messages are being received by the second ListView, but it's not processing them for some reason.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top