Unplanned
Last Updated: 29 Oct 2024 17:24 by Martin Ivanov
Martin Ivanov
Created on: 29 Oct 2024 17:24
Category: DataGrid
Type: Bug Report
0
DataGrid: The click actions stop working when the data grid is hosted in a TabControl

The click actions (like cell selection and sorting) stop working when RadDataGrid is hosted in a RadTabControl or TabView. To reproduce this, you should select the tab item with the data grid, then select another tab, and select back the tab with the data grid. This prevents the hit testing in the RadDataGrid element.

The issue occurs because the hit test service used in the RadDataGrid implementation. The hit test service relies on the IsLoaded property of RadDataGrid (inherited from RadControl). The property is set in the Loaded and Unloaded events. However, when switching tabs, the Unloaded event is invoked on deselection, but on second selection of the same tab, the Loaded event is never called again,  thus IsLoaded is false. This seems like an issue in WinUI.  Something very similar is reported here.

To work this around, you can subscribe to the PreviewSelectionChanged event of RadTabControl and manually update the internal isLoaded field of the data grid.

 private void RadTabControl_PreviewSelectionChanged(object sender, Telerik.UI.Xaml.Controls.RadSelectionChangedEventArgs e)
 {
     if (e.AddedItems.Count > 0)
     {
         var gridView = ((RadTabItem)e.AddedItems[0]).Content as RadDataGrid;
         var isLoadedField = typeof(RadControl).GetField("isLoaded", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
         isLoadedField.SetValue(gridView, true);
     }
 }

0 comments