0
votes

I have a ListView in which i want to create an event when the VScrollBar appears. I actully dont want a horizontal scrollbar and whenever the VScrollbar appears i want to resize the columns so that it fits the window. I already can check for the visiblity of a scrollbar but i dont know the name of the event which is triggered when the ScrollBars appear. Here is my code :

    private const int WS_VSCROLL = 0x200000;
    private const int GWL_STYLE = -16;
    [DllImport("user32.dll")]
    public static extern int GetWindowLong(IntPtr hWnd, int Index);
    private static bool IsScrollbarVisible(IntPtr hWnd)
    {
        bool bVisible = false;
        int nMessage = WS_VSCROLL;
        int nStyle = GetWindowLong(hWnd, GWL_STYLE);
        bVisible = ((nStyle & nMessage) != 0);
        return bVisible;
    }

And Works Like this :

    if (IsScrollbarVisible(listview.Handle))
    {
          columnHeader1.Width = listview.ClientRectangle.Width - (columnHeader2.Width + columnHeader3.Width);
    }

Someone Please Help Me!

1
If your the only intent is to control scrollbars over a ListView, there could be one simple solution. You create a Panel and a ListView on it. The Panel is inherited from ScrollableControl class so you can sontrol the vertical and horizontal scrollbars through it. It is not a direct answer to your question. If it is what you need I could place it as an answer.MajesticRa

1 Answers

2
votes

ClientSizeChanged Event will fire but to get it work correct we have to add BeginUpdate() and EndUpdate()..

This Code does everything :

    private void listview_ClientSizeChanged(object sender, EventArgs e)
    {
        listview.BeginUpdate();
        if (IsScrollbarVisible(listview.Handle))
        {
            columnHeader1.Width = listview.ClientRectangle.Width - (columnHeader2.Width + columnHeader3.Width);
        }
        listview.EndUpdate();
    }