none
Treeview control horizontal scrollbar issue RRS feed

  • Question

  • Hi All,

    I have the following issue when using treeview control of VS 2005 in my windows Forms Application.

     

    I have some nodes in the tree which is lengthier than the tree view control, in which case horizontal scrollbar automatically comes in.

     

    I have made the horizontal scrollbar positioned to the left most corner of the control.Now i have right clicked on a node and chose the option "Update" which does some internal work and finally makes the horizontal scrollbar automatically scrolled to the center position.

     

    I do not want the horizontal scrollbar scrolled automatically to the center position of the treeview control.

     

    Please help me in stopping this behaviour through code.

     

    Application environment:

    Windows Forms

    VS 2005

    C#

    Monday, June 9, 2008 8:09 PM

Answers

  •  

    Hi pkarun,

    Sorry I cannot reproduce this problem. But to force the horizontal scrollbar to scroll to the left, we can send the WM_HSCROLL message to the TreeView to force it to the left. Here is the sample code for your information:

    Code Snippet

            const int WM_HSCROLL = 0x0114;

            const int SB_LEFT = 6;

     

            [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]

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

     

            private void button1_Click(object sender, EventArgs e)

            {

                SendMessage(this.treeView1.Handle, WM_HSCROLL, SB_LEFT, 0);

            }

     

    Let me know if this helps, if not, could you please show us how you update the database? Some code would be helpful.

    Best regards.
    Rong-Chun Zhang

    Windows Forms General FAQs
    Windows Forms Data Controls and Databinding FAQs

    Friday, June 13, 2008 12:54 PM

All replies

  • It's not clear to me what "Update" means.  Is the LabelEdit property set to True and do you edit the node label?
    Tuesday, June 10, 2008 1:53 AM
    Moderator
  • Hi nobugz,

    Thanks for showing interest in helping me.

    Actually "Update" is the context menu written by me which does updates the selected node values into the database.

    The point is once it is done the horizontal scrollbar of the treeview control comes to the middle automatically.

    I do not want the horizontal scrollbar coming to the middle.Juzt want the horizontal scrollbar stay where it is earlier before i chose "Update" context menu.

     

    Is there anyway to restrict the horizontal scrollbar behaviour of the treeview control programmatically.

     

    Help me on this.

    your help is highly appreciated.Thanks.

    Wednesday, June 11, 2008 2:47 PM
  •  

    Hi pkarun,

    Sorry I cannot reproduce this problem. But to force the horizontal scrollbar to scroll to the left, we can send the WM_HSCROLL message to the TreeView to force it to the left. Here is the sample code for your information:

    Code Snippet

            const int WM_HSCROLL = 0x0114;

            const int SB_LEFT = 6;

     

            [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]

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

     

            private void button1_Click(object sender, EventArgs e)

            {

                SendMessage(this.treeView1.Handle, WM_HSCROLL, SB_LEFT, 0);

            }

     

    Let me know if this helps, if not, could you please show us how you update the database? Some code would be helpful.

    Best regards.
    Rong-Chun Zhang

    Windows Forms General FAQs
    Windows Forms Data Controls and Databinding FAQs

    Friday, June 13, 2008 12:54 PM
  • Hi Rong-Chun Zhang,

    WOWWWWW its really great.

    Your piece of code really worked.Thanks a ton for helping me out.Thanks again for all your help.

     

    Thanks & Regards,

    Arun

    Wednesday, June 25, 2008 7:02 PM