How to detect the vertical scrollbar in a DataGridView control

后端 未结 7 751
半阙折子戏
半阙折子戏 2021-01-05 05:19

Using winforms in vs2008. I have a DataGridView and I would like to detect when the vertical scroll bar is visible. What event should I register for?

I am adding the

7条回答
  •  天命终不由人
    2021-01-05 05:54

    Overriding DGV behavior is usually a huge pain in the neck. Got this going pretty quickly though. Add a new class to your form and paste the code shown below. Compile. Drop the new control from the top of the toolbar onto a form. Implement the ScrollbarVisibleChanged event.

    using System;
    using System.Windows.Forms;
    
    class MyDgv : DataGridView {
        public event EventHandler ScrollbarVisibleChanged;
        public MyDgv() {
            this.VerticalScrollBar.VisibleChanged += new EventHandler(VerticalScrollBar_VisibleChanged);
        }
        public bool VerticalScrollbarVisible {
            get { return VerticalScrollBar.Visible; }
        }
        private void VerticalScrollBar_VisibleChanged(object sender, EventArgs e) {
            EventHandler handler = ScrollbarVisibleChanged;
            if (handler != null) handler(this, e);
        } 
    }
    

提交回复
热议问题