I have a DataGrid in my project where I am hiding the column headers. When user clicks on a button, I want to sort grid based on first column.
But when I dont hide mu column header and click on it, it sorts column. Please help.
What I have tried:
I tried following code which is not working
public MainWindow()
{
InitializeComponent();
dataGrid1.Loaded += (s, e) =>
{
dataGrid1.Sorting -= DataGrid1_Sorting;
dataGrid1.Sorting += DataGrid1_Sorting;
};
}
private void DataGrid1_Sorting(object sender, DataGridSortingEventArgs e)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
{
DataGrid1_Sorting(dataGrid1, new DataGridSortingEventArgs(dataGrid1.Columns[0]));
}