Skip to content

Latest commit

 

History

History
29 lines (26 loc) · 1.3 KB

File metadata and controls

29 lines (26 loc) · 1.3 KB

How to select rows in a WPF DataGrid using RowHeaderIndentCell?

In a WPF DataGrid (SfDataGrid), the default behavior does not allow for the selection of all rows when the RowHeaderIndentCell is clicked. However, you can implement this functionality by handling the MouseUp event. This event can be used to select all rows programmatically by accessing the row and column indices.

public MainWindow()
{
   InitializeComponent();
   dataGrid.MouseUp += DataGrid_MouseUp;
}

private void DataGrid_MouseUp(object sender, MouseButtonEventArgs e)
{
   var point = e.GetPosition(this);
   var rowColumnIndex = dataGrid.GetVisualContainer().PointToCellRowColumnIndex(point);
   if (rowColumnIndex.ColumnIndex == 0 && rowColumnIndex.RowIndex == 0)
   {
       if (dataGrid.SelectedItems.Count  > 1)
       {
           dataGrid.ClearSelections(false);
       }
       else
       {
           dataGrid.SelectAll(); 
       }     
   }          
} 

image.png