开发者

How can I find which column header is selected?

开发者 https://www.devze.com 2023-02-28 18:54 出处:网络
I have a datagrid view in my form and I like to sort the table by clicking the columnheader. Ichoose the Columnheader Dou开发者_JAVA技巧bleClick Event for writing the code but I don\'t know, how I sh

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号