How can I find which column header is selected?
I have a datagrid view in my form and I like to sort the table by clicking the columnheader.
I choose the Columnheader Dou开发者_JAVA技巧bleClick Event for writing the code but I don't know, how I should tell which column header is selected.
Is there any way for it or I have to change my mind?
Look at the DataGridView's ColumnHeaderMouseClick event.
When the event fires you can get the index value of the clicked column through the event's DataGridViewCellMouseEventArgs.ColumnIndex property. The article I linked has an example.
In both ColumnHeaderMouseClick
and OnColumnHeaderMouseDoubleClick
events you can do:
private void DataGridView1_OnColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
int column = e.ColumnIndex;
}
精彩评论