Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Datagrid enter/return key goes to next row.

$
0
0

Hi,

I have a DataGrid and I want to stop the enter key from sending the selected row to the next row.  I have looked around and found suggestions to do it as below but both solutions don't work for me.  (However, when I run in a debugger and insert a breakpoint during exection - it then works, but not in normal execution of the application).

private void _curveCategoryGrid_KeyDown(object sender, KeyEventArgs e)
{
            if ((e.Key.Equals(Key.Enter)) || (e.Key.Equals(Key.Return)))
            {
                return;
            }
}
private void _curveCategoryGrid_PreviewKeyDown(object sender, KeyEventArgs e)
{
            if ((e.Key.Equals(Key.Enter)) || (e.Key.Equals(Key.Return)))
            {
                return;
            }
}

Any suggestions as to how I can stop the next row from being selected?  Not the cell that will be selected will be an editable cell so need to be able to process the CellEditEnding event before cancelling the selection of the next row.

A messy solution I konw worls is that I keep a copy of the currently selected row and after the key press has been processed I set the selected row back to the one before I pressed enter.  I'm assuming there is a cleaner way than this though.

Thanks in advance.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>