本文介绍了在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项目并复制粘贴以下代码: -

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中单击行标题的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 23:03