DataGridView覆盖顶部,左侧标题单元格(选择全部) [英] DataGridView override top,left header cell click (select all)

查看:403
本文介绍了DataGridView覆盖顶部,左侧标题单元格(选择全部)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想覆盖DataGridView标题/列单元格(顶部,左侧单元格)中的鼠标单击行为。该单元格导致所有行被选择。相反,我想阻止它选择所有行。我看到RowHeaderSelect和ColumnHeaderSelect的一个事件,但是没有一个用于该顶部,左标题单元格的事件。

I want to override the behavior of a mouse click in the DataGridView header/column cell (top, left cell). That cell causes all rows to be selected. Instead, I want to stop it from selecting all rows. I see an event for RowHeaderSelect and ColumnHeaderSelect but not one for that top, left header cell.

任何想法?我只是在盲目吗?

Any ideas? Am I just being blind?

推荐答案

这是您单击该单元格时会发生什么的消除的代码:

This is the dissasembled code of what happens when you click that cell:

private void OnTopLeftHeaderMouseDown()
{
    if (this.MultiSelect)
    {
        this.SelectAll();
        if (-1 != this.ptCurrentCell.X)
        {
            this.SetCurrentCellAddressCore(this.ptCurrentCell.X, this.ptCurrentCell.Y, false, false, false);
        }
    }

为了防止这种行为,你有2解决方案:

In order for you to prevent this behavior you have 2 solutions:


  1. 禁用多选(如果您的业务逻辑允许)

  2. 继承您的自己的datagrid和覆盖 OnCellMouseDown (这样的东西)

protected override void OnCellMouseDown(DataGridViewCellMouseEventArgs e)
{
    if (e.RowIndex == -1 && e.ColumnIndex == -1) return;
    base.OnCellMouseDown(e);
}


这篇关于DataGridView覆盖顶部,左侧标题单元格(选择全部)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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