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?
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!");
}
}
You can get the row header by following code:
Private Sub dataGridView1_RowHeaderMouseClick( _
ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs) _
Handles dataGridView1.RowHeaderMouseClick
Me.dataGridView1.SelectionMode = _
DataGridViewSelectionMode.RowHeaderSelect
Me.dataGridView1.Rows(e.RowIndex).Selected = True
End Sub
or
void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
//
// Do something on double click, except when on the header.
//
if (e.RowIndex == -1)
{
//this is row header...
some code here.
}
Code...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With