Hi,
This should be the simplest thing but I've had real issues trying to get it working. Does anyone know how to alter the behaviour of the XamDataGrid so that when your in the last column and press the right arrow it dosen't jump down to the first column of the next line (simular to left arrow)? I.e. behave more like Excel does. I've tried hooking into ExecutingCommand and catching the CellRight/CellLeft commands but while this works most of the time, occasionally (when key pressed a lot) something else gets called and it jumps to the undesired location.
thanks
On my end I cannot make it to fail. One thing that you can try is to use the Active cell not the Selected. Activation happens before selection so this could be causing this. Also, it might happen that you have multiple selected fields, but you can have only one active cell :
e.Cancel = (0 == string.Compare(checkField, (sender as XamDataGrid).ActiveCell.Field.Name));
FYI using the above code with a minro change ( lookin ay key rather that command name) and handling to key down preview event instead of the Executecommand event seems to work without issue.
The following code does the job except it fails every so often. Easiest way to force it to fail is to keep the right arrow pressed and click the mouse on another right most cell. That nearly always results in the undesired behaviour and the handler below not being called to stop it. But every so often just pushng the button continously will cause it to happen.
void
idg_ExecutingCommand(object sender, Infragistics.Windows.Controls.Events.ExecutingCommandEventArgs
e)
{
bool bCellRight = false
;
bool bCellLeft = false
string checkField = null
if( 0 == string.Compare( e.Command.Name , "CellRight"
) )
bCellRight =
true
checkField = ((
XamDataGrid
)sender).FieldLayouts[0].Fields.Last().Name;
}
else if( 0 == string.Compare(e.Command.Name, "CellLeft"
bCellLeft =
)sender).FieldLayouts[0].Fields.First().Name;
if
( bCellRight || bCellLeft )
if( 1 == ((XamDataGrid
)sender).SelectedItems.Cells.Count )
e.Cancel = ( 0 ==
string.Compare( checkField , ((Cell)((XamDataGrid
)sender).SelectedItems.First()).Field.Name ) );
else
e.Cancel =
Hello,
Handling and canceling the ExecutingCommand event is the recommended approach. Can you provide us with an example of when this incorrect behavior occurs. Another way would be to handle the PreviewKewDown event of the XamDataGrid and handle it for the left and right arrow keys if the active cell is respectively in the beginning or end of the record.