如何检测垂直滚动条在DataGridView控件 [英] How to detect the vertical scrollbar in a DataGridView control

查看:107
本文介绍了如何检测垂直滚动条在DataGridView控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VS2008中使用的WinForms。我有一个DataGridView,我想检测时,垂直滚动条是可见的。我要报名参加什么活动吗?

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?

我加入在网格的最后一列的总结了每个单元的值,并在在DataGridView的底部显示在文本框该值。

I am adding the summing the each cell value in the last column of the grid and displaying that value in a textbox at the bottom of the DataGridView.

我想这个文本框保持排队的单元格值(我已经让他们右对齐,因为它是$$值)即使在滚动条present。

I would like this textbox to stay lined up with the cell values (I have made them right aligned since it is $$ values) even after the scroll bar is present.

推荐答案

重写DGV行为通常是在脖子上一个巨大的痛苦。很快,虽然有这个打算pretty的。添加一个新类到您的窗体和粘贴下面所示的code。编译。删除从工具栏上方的新控件到窗体上。实施ScrollbarVisibleChanged事件。

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);
    } 
}

这篇关于如何检测垂直滚动条在DataGridView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆