Showing posts with label WPF DataGrid DataGridBoundColumn DataGridCell GenerateEditingElement PrepareCellForEdit doubleclick focus currentcell generateelement. Show all posts
Showing posts with label WPF DataGrid DataGridBoundColumn DataGridCell GenerateEditingElement PrepareCellForEdit doubleclick focus currentcell generateelement. Show all posts

Wednesday, September 21, 2011

Focus is lost when GenerateEditingElement is overridden

When deriving from DataGridBoundColumn to override control creation for your DataGrid, you are going to face a problem.. Where does my focus go when I double click the cell?

The cell control is created and activated but the focus just goes to the parent DataGridCell leaving the control that I just created in GenerateEditingElement unfocused. So I will have to click a third click to get the focus where I wanted it in the first place.

The solution is to override DataGridBoundColumn.PrepareCellForEdit and set the focus there. Voila.