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 10th, 2008, 02:54 AM
Registered User
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Scroll bar problem - simple

Heya folks!
This one must be too simple to feature on a forum but its something that isn't coming thru for quite some time now!
I have two listview controls that i customized by overriding the WndProc() in order to capture their scroll events.Now I am attempting to use a common scrollbar for the two so that when that main scrolbar scrolls the listview scrollbars also scroll. Currently i am able to scroll the listview downwards but not able to scroll them back up.

Here's the customization part
Code:
[DllImport("user32.dll")]

        static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

        [DllImport("user32.dll")]

        static extern int SetScrollPos(IntPtr hWnd, int nBar, int nPos, bool bRedraw);

 

        private const int WM_HSCROLL = 0x114;

        private const int WM_VSCROLL = 0x115;

        private const int SBS_HORZ = 0;

        private const int SBS_VERT = 1;

 

        void listView1_Scroll(object sender, MyScrollEventArgs e)

        {

            ListViewEx listVw = sender as ListViewEx;

 

            Int16 hi = (Int16)((int)e.WParam >> 16);//position

            Int16 lo = (Int16)e.WParam;//scroll type

 

            if (e.Orientation == ScrollOrientation.VerticalScroll)

            {

                if (lo == 5) //SB_THUMBTRACK

                {

                    if (SetScrollPos(this.listView2.Handle, SBS_VERT, hi, true) != 0)

                    {

                        SendMessage(this.listView2.Handle, WM_VSCROLL,
                          (IntPtr)(4 + 0x10000 * hi), IntPtr.Zero);

                    }    

                }

                else

                {

                    SendMessage(this.listView2.Handle, WM_VSCROLL, e.WParam, IntPtr.Zero);

                }

            }

            if (e.Orientation == ScrollOrientation.HorizontalScroll)

            {

                if (lo == 5)//SB_THUMBTRACK

                {

                    SetScrollPos(this.listView2.Handle, SBS_HORZ, hi, true);

                    SendMessage(this.listView2.Handle, WM_HSCROLL,
                       (IntPtr)(4 + 0x10000 * hi), IntPtr.Zero);

                }

                else

                {

                    SendMessage(this.listView2.Handle, WM_HSCROLL, e.WParam, IntPtr.Zero);

                }

            }
And here's the scroll calls that i was originally using and was partially working. I couldn't get the scrollbars to scroll with this, only thumb tracks would scroll each other.

Code:
                int16 hi = (int16)((int)e.wparam >> 16);
                int16 lo = (int16)(int)e.wparam;
                intptr temp;
                if (e.orientation == scrollorientation.verticalscroll)
                {
                    if (lo == 5)
                    {
                        if (setscrollpos(this.listviewex2.handle, sbs_vert, hi, true) != 0)
                        {
                            temp = (intptr)(4 + 0x10000 * hi);
                            postmessage(this.listviewex2.handle, wm_vscroll, temp, intptr.zero);
                            //sendmessage(this.listviewex2.handle, wm_vscroll, (intptr)(4 + 0x10000 * hi), intptr.zero);
                        }
                    }
                    else
                    {
                        postmessage(this.listviewex2.handle, wm_vscroll, e.wparam, intptr.zero);
                        //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);
                        postmessage(this.listviewex2.handle, wm_hscroll, (intptr)(4 + 0x10000 * hi), intptr.zero);
                        //sendmessage(this.listviewex2.handle, wm_hscroll, (intptr)(4 + 0x10000 * hi), intptr.zero);
                    }
                    else
                    {
                        postmessage(this.listviewex2.handle, wm_hscroll, e.wparam, intptr.zero);
                        //sendmessage(this.listviewex2.handle, wm_hscroll, e.wparam, intptr.zero);
                    }
                }
            }

            catch (exception ex)
            {
                messagebox.show(ex.tostring());
            }
There are a couple of things I wanna know here.
1. How do i scroll one scrollbar from any other.
2. How do i use a main control scrollbar to scroll the two listview scrollbars?
3. How do i make the scrollbars to scroll back up from the lowered state?

I have failed to draw any logic on how to make sure that the two listview scroll bar events don't send each other on an infinite loop.
Plus, I need to scroll them by thumbtracks + scrollbars + mouse scroll wheel!

Somebody! please help me!

-
Roger

-
Roger
 
Old April 10th, 2008, 07:42 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

I thought we already covered this? I gave you links to websites on how to solve this?

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 11th, 2008, 01:20 AM
Registered User
 
Join Date: Apr 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Rob,
Nope! The other threads that you redirected me to didn't provide me the information that i was actually looking for. I managed to scroll the listviews synchronously with the thumbtrack of the first listview. but when i use either the keyboard to scroll or the mouse scroll wheel, or even the scrollbar itself(the bar) they listviews dont sync. That is the problem is am trying to solve here. Need help with those issues.

-
Roger

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

In that case, I am not too sure then, I guess it would need more digging and hacking to get it running since it is obviously not supported. Is this for a business application or study project?

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://robzyc.spaces.live.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to control scroll bar BurhanKhan Javascript 3 August 26th, 2004 02:31 PM
How can I make two scroll bar to be the same one? Daniel_hn Visual C++ 1 September 16th, 2003 09:28 AM
css and scroll bar markhardiman HTML Code Clinic 3 July 18th, 2003 04:55 AM
Scroll Bar cooldude87801 BOOK: Beginning Java 2 0 June 18th, 2003 11:59 AM





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