事件单击行标题中的DataGridView [英] Event for clicking on row headers in DataGridView

查看:100
本文介绍了事件单击行标题中的DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是专门处理鼠标单击只在DataGridView中的行标题?

What is the event that exclusively handles mouse clicks made only on Row Headers of DataGridView?

如果有没有,这将是处理这类事件的方法吗?

If there are none, what would be an alternative of handling this type of event?

推荐答案

有一个新的WinForms项目和复制粘贴下面的code: -

Have a new Winforms Project and copy-paste the code below :-

public partial class Form1 : Form
{
    public Form1()
    {
        var list = new List<Books>
                       {
                           new Books() {Title = "Harry Potter", TotalRating = 5},
                           new Books() {Title = "C#", TotalRating = 5}
                       };
        InitializeComponent();
        dataGridView1.AutoGenerateColumns = true;
        dataGridView1.DataSource = list;
        dataGridView1.RowHeaderMouseClick += new DataGridViewCellMouseEventHandler(OnRowHeaderMouseClick);
    }

    void OnRowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        MessageBox.Show("Clicked RowHeader!");
    }
}

这篇关于事件单击行标题中的DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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