Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 1st, 2008, 01:04 AM
Registered User
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with ListView Control in C#

Hello there!
I am trying to build an application here which I have to produce for my examination in a few days. A part of the appearance of the project requires me to use two listviews. The working of the project is such that the contents of the listview are compared against each other and the difference is picked from em. That part is handled. Now the issue is that I need to synchronize the listview control's scroll bars so that when listview1 is scrolled down even the listview2 is also scrolled down to the same level as listview1, and the same vice versa. Both, the horizontal and vertical scrollbars are to be synced.
Can somebody please help me with this issue? I have been trying this for well over a month but with no luck. I'd be grateful to whoever saves me out here!!
Please! HELP!

-
Roger
 
Old April 1st, 2008, 02:03 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi There,

I have just googled this and found many pages with direct links to source code on how to do this. Try running a google :)

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>
 
Old April 2nd, 2008, 01:45 AM
Registered User
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i tried those Rob, but no luck with any of em.
Meanwhile, what search string did you try and get results?
I tried customising a scrollbar control to trigger the listvoew but i can get a Panel control to scroll and not a ListView control. Panel has an AutoScrollPosition that i can use. What can I do for the ListView control? Please help, I am stuck!

-
Roger
 
Old April 2nd, 2008, 02:25 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Roger,

I first searched for "ListView Scroll Event" - since I know there is no actual event for this, to see how other people have implemented it.

Following a read of that, I then searched for "ListView Set Scroll" to see if there is a way to set the scroll position, there is a whammy of a result right at the top! :D

Good Luck - let us know how you get on! :)

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>
 
Old April 2nd, 2008, 05:06 AM
Registered User
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Rob,
Thanks for the response!
Well, I did try the routes you asked me to take but i found success with scrolling nearly all the components than the ListView Control!!!

Somehow cant seem to get that thing to work!

-
Roger

-
Roger
 
Old April 2nd, 2008, 05:36 AM
Registered User
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rob, I manage to achieve this much now

Code:
public class ListViewEx:ListView
{
    private const int WM_HSCROLL    = 0x0114;
    private const int WM_VSCROLL    = 0x0115;
    private const int WM_KEYDOWN    = 0x0100;
    private const int WM_MOUSEWHEEL = 0x020A;

    public event System.EventHandler ScrollEvent;

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == WM_VSCROLL  || 
            m.Msg == WM_HSCROLL  ||
            m.Msg == WM_KEYDOWN     ||
            m.Msg == WM_MOUSEWHEEL)
            if (ScrollEvent != null)
                ScrollEvent (this, null);


        base.WndProc (ref m);
    }

}
Got a listview event to happen. Now, how do i get a property to happen? A ScrollPosition or a AutoScrollPostion or anything at that will allow me use the scroll to position??

Expecting another response from you!

-
Roger
 
Old April 3rd, 2008, 05:41 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Roger,

Both of them give you links to sites that actually contain the code for both requirements?

Have you tried calling Invalidate() to cause a repaint when the scroll event occurs?

Not able to test this myself at the moment as busy at work, may have a look into it later though..

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>
 
Old April 7th, 2008, 04:25 AM
Registered User
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Managed to create a custom listview control now. But when i try to make a scroll event trigger i am facing a stack overflow problem. i am guessing my code's taking me into an infinite loop and so the overflow.
Code:
if (e.Orientation == ScrollOrientation.VerticalScroll)
                {
                    if (lo == 5)
                    {
                        if (SetScrollPos(this.listViewEx2.Handle, SBS_VERT, hi, true) != 0)
                        {
                            SendMessage(this.listViewEx2.Handle, WM_VSCROLL, (IntPtr)(4 + 0x10000 * hi), IntPtr.Zero);
                        }
                    }
                    else
                    {
                        SendMessage(this.listViewEx2.Handle, WM_VSCROLL, e.WParam, IntPtr.Zero);
                    }
                }

                if (e.Orientation == ScrollOrientation.HorizontalScroll)
                {
                    if (lo == 5)
                    {
                        SetScrollPos(this.listViewEx2.Handle, SBS_HORZ, hi, true);
                        SendMessage(this.listViewEx2.Handle, WM_HSCROLL, (IntPtr)(4 + 0x10000 * hi), IntPtr.Zero);
                    }
                    else
                    {
                        SendMessage(this.listViewEx2.Handle, WM_HSCROLL, e.WParam, IntPtr.Zero);
                    }
                }
-
Roger





Similar Threads
Thread Thread Starter Forum Replies Last Post
About Listview control yuetqu BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 August 15th, 2006 04:56 AM
Refreshing a ListView control osemollie Pro VB 6 1 July 26th, 2006 10:00 AM
ListView Control JelfMaria VB How-To 4 May 5th, 2005 12:39 AM
ListView Control jlr27613 C++ Programming 1 September 14th, 2004 12:58 PM
listview control jakeone Beginning VB 6 1 March 9th, 2004 08:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.