DataGridView::ColumnHeaderMouseClick Event

 

Occurs when the user clicks a column header.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
event DataGridViewCellMouseEventHandler^ ColumnHeaderMouseClick {
	void add(DataGridViewCellMouseEventHandler^ value);
	void remove(DataGridViewCellMouseEventHandler^ value);
}

For more information about handling events, see NIB: Consuming Events.

When a column heading is clicked in a DataGridView, the default behavior is to order the grid rows based on the clicked column, or to reverse the sort order if the grid is already sorted by the clicked column. The following code example demonstrates how to use this event to perform a programmatic sort that emulates the default behavior of clicking a DataGridViewColumnHeaderCell when the default behavior has been disabled. In this example, theSelectionMode is set to ColumnHeaderSelect, so clicking the DataGridViewColumnHeaderCell selects the contents of the column. For the example code to function as intended, the default column header click behavior needs to be changed each time the data is loaded into the DataGridView. Add a DataBindingComplete event handler to provide the code that changes the default behavior. To run this example, paste the code into a form that contains a DataGridView named dataGridView1 and ensure that all events are associated with their event handlers.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: