|
Queries |
Response |
|
Add New Row when Tab key is pressed from the last column Instead Of Enter Key & move the CurrentCell to the first column of the AddNewRow |
We cannot handle the new row adding with handling keys. But the reported scenario of adding the new row while adding data in the last column can be done by handling the RowValidating event. Please refer to the following code.
Code Example:
// Wiring event.
sfDataGrid1.RowValidating += SfDataGrid1_RowValidating;
private void SfDataGrid1_RowValidating(object sender, RowValidatingEventArgs e)
{
if (this.sfDataGrid1.IsAddNewRowIndex(e.DataRow.RowIndex))
{
var lastColumnIndex = sfDataGrid1.Columns.IndexOf(sfDataGrid1.Columns.LastOrDefault());
var hasDetailsView = sfDataGrid1.DetailsViewDefinitions != null && sfDataGrid1.DetailsViewDefinitions.Count > 0;
var rowHeader = sfDataGrid1.ShowRowHeader;
var indentCount = sfDataGrid1.View.GroupDescriptions.Count;
var lastCellIndex = lastColumnIndex + indentCount + Convert.ToInt32(rowHeader) + Convert.ToInt32(hasDetailsView);
if (this.sfDataGrid1.CurrentCell.ColumnIndex != lastCellIndex)
e.IsValid = false;
}
}
|
|
How to move the CurrentCell to the first column of the AddNewRow when the Tab key is pressed from the last column and its position is at the Bottom of the SfDataGrid?
|
Since we cannot handle the add new process in Key handling, we can move the current cell to first cell of newly added row after a row is added through RowValidated event. Please refer to the following code.
Code Example:
// Wiring event.
sfDataGrid1.RowValidated += SfDataGrid1_RowValidated;
private void SfDataGrid1_RowValidated(object sender, RowValidatedEventArgs e)
{
if (this.sfDataGrid1.IsAddNewRowIndex(e.DataRow.RowIndex))
{
int firstColumnIndex = sfDataGrid1.Columns.IndexOf(sfDataGrid1.Columns.FirstOrDefault(x => x.Visible && x.ActualWidth != 0));
var hasDetailsView = sfDataGrid1.DetailsViewDefinitions != null && sfDataGrid1.DetailsViewDefinitions.Count > 0;
var rowHeader = sfDataGrid1.ShowRowHeader;
var indentCount = sfDataGrid1.View.GroupDescriptions.Count;
var firstCellIndex = firstColumnIndex + indentCount + Convert.ToInt32(rowHeader) + Convert.ToInt32(hasDetailsView);
this.sfDataGrid1.MoveToCurrentCell(new RowColumnIndex(e.DataRow.RowIndex, firstCellIndex));
}
} |
|
Added Row should be available in sfDataGrid.View |
Yes, the added row will be available in sfDataGrid.View.Records once it is committed. |