I am now trying a different route by looking at the SelectionChanged event on the grid itself, and then trying to get a handle on the textbox contained within the cell. Is there any way to go from a DataGridCellInfo object to the UIElements/controls that make up that cell so that I can get a handle on the textbox within that cell?
Is there another way to do this such as getting notified when new cells are created vs recycled in the virtualization so that I could add/remove event handlers there?
Thanks for any suggestions!
5 Answers, 1 is accepted
Thank you for contacting us.
In order to add event handlers for each cell's element, you need to hook the event handler in the DataTemplate of the desired column. For example:
<telerikGrid:DataGridTemplateColumn.CellContentTemplate> <DataTemplate> <TextBlock GotFocus="TextBlock_GotFocus"/> </DataTemplate></telerikGrid:DataGridTemplateColumn.CellContentTemplate>Let me know if this works for you.
Regards,
Ivaylo Gergov
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
{Windows.UI.Xaml.UnhandledExceptionEventArgs} Exception: {"Error HRESULT E_FAIL has been returned from a call to a COM component."} Handled: false Message: "System.Runtime.InteropServices.COMException\r\n at Windows.UI.Xaml.DataTemplate.LoadContent()\r\n at Telerik.UI.Xaml.Controls.Grid.DataGridTemplateColumn.CreateContainer(Object rowItem)\r\n at Telerik.UI.Xaml.Controls.Grid.View.XamlContentLayer.GenerateCellContainer(Object rowItem, DataGridColumn definition)\r\n at Telerik.UI.Xaml.Controls.Grid.XamlGridCellGenerator.Telerik.UI.Xaml.Controls.Grid.IUIContainerGenerator<Telerik.UI.Xaml.Controls.Grid.GridCellModel,Telerik.UI.Xaml.Controls.Grid.CellGenerationContext>.GenerateContainerForItem(CellGenerationContext info, Object containerType)\r\n at Telerik.UI.Xaml.Controls.Grid.CellModelGenerator.GenerateContainerForItem(CellGenerationContext context, Object containerType)\r\n at Telerik.UI.Xaml.Controls.Grid.ItemModelGenerator`2.GenerateContainer(K context)\r\n at Telerik.UI.Xaml.Controls.Grid.CellsController`1.GetCellDecorator(IItemInfoNode parentRow, ItemInfo columnItemInfo, Int32 rowLine, Int32 columnLine)\r\n at Telerik.UI.Xaml.Controls.Grid.CellsController`1.GenerateCellsForRow(IItemInfoNode rowDecorator, Int32 rowSlot)\r\n at Telerik.UI.Xaml.Controls.Grid.GridModel.GenerateCellsForReadOnlyRow(Int32 rowSlot, Double largestRowElementWidth, IItemInfoNode rowDecorator)\r\n at Telerik.UI.Xaml.Controls.Grid.GridModel.Telerik.UI.Xaml.Controls.Grid.ITable.GenerateCellsForRow(Int32 rowSlot, Double largestRowElementHeight, IItemInfoNode rowDecorator)\r\n at Telerik.UI.Xaml.Controls.Grid.NodePool`2.GenerateCellsForLine(Int32 slot, Double largestLength, T lastElement)\r\n at Telerik.UI.Xaml.Controls.Grid.NodePool`2.GenerateContainer(IList`1 itemInfos)\r\n at Telerik.UI.Xaml.Controls.Grid.NodePool`2.OnMeasure(RadSize availableSize, Double offset)\r\n at Telerik.UI.Xaml.Controls.Grid.GridModel.MeasureCells(RadSize newAvailableSize)\r\n at Telerik.UI.Xaml.Controls.Grid.RadDataGrid.OnCellsPanelMeasure(RadSize newAvailableSize)\r\n at Telerik.UI.Xaml.Controls.Grid.Primitives.DataGridCellsPanel.MeasureOverride(Size availableSize) at Windows.UI.Xaml.UIElement.Measure(Size availableSize)\r\n at Telerik.UI.Xaml.Controls.Grid.Primitives.DataGridRootPanel.MeasureOverride(Size availableSize)"Is there a way to go from a selected cell to it's contained UIElements instead?
Unfortunately, it would not be possible to access the UI element that represents the selected cell. The main reason is that the RadDataGrid uses UI virtualization.
Could you please send us a sample project that reproduces the exception? Thus, we will be able to further investigate.
I am looking forward to your reply.
Regards,
Ivaylo Gergov
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
In a simple data template you might have a textbox as well as other things like a label, etc. in each cell. Is there no way then for the selection of a cell to in turn put the focus on the contained textbox?
I have to admit that there is a bug with the RadDataGrid - when you select a cell from a templated column, the first focusable element of the grid gets the focus instead of the content of the selected cell. I have redirected this issue to our developers and they will do their best to fix it for the official release(planned for mid-October). I have also updated your Telerik points as a token of gratitude for bringing this issue to our attention.
Feel free to contact us if you have any other questions or ideas.
Rositsa Topchiyska
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.