Editing does not start when typing "." character using GridCurrencyColumn column
Hi,
I have an SfDatagrid with a GridCurrencyColumn column inside it.
The user can edit and modify the content of this currency cell.
If the cell has focus on it but it is not in editing mode, as soon the user types a digit character the cell goes in edit mode and the digit is correctly added to the cell value.
But if the user types "." character to start a price that is less than one (say some cents), the cell does not go in edit mode and the "." char is not added to the value.
In order to make this kind of input input the user if forced to click another time with the mouse on that cell and force it to go in edit mode or to type "0" before typing ".".
Is there a way to begin editing on this kind of cells only typing "." character ?
Thank you.
Silvio Scattaglia
SIGN IN To post a reply.
6 Replies
SV
Srinivasan Vasu
Syncfusion Team
September 1, 2017 05:30 AM UTC
Hi Silvio,
Thanks for contacting Syncfusion support.
We have checked your query and we have prepared a sample as per your requirement. By default, SfDataGrid doesnot allow the GridCell to go to edit mode, while pressing the dot(.) key in GridCurrencyColumn. You can achieve this requirement, by customizing the SfDataGrid class, and override the OnTextInput method.
Please refer the below code example.
|
public class SfDataGridExt : SfDataGrid
{
public SfDataGridExt()
: base()
{
}
protected override void OnTextInput(TextCompositionEventArgs e)
{
if (!SelectionController.CurrentCellManager.HasCurrentCell)
{
base.OnTextInput(e);
return;
}
//Get the Current Row and Column index from the CurrentCellManager
var rowColumnIndex = SelectionController.CurrentCellManager.CurrentRowColumnIndex;
RowGenerator rowGenerator = this.RowGenerator;
//Get the row from the Row index
var dataRow = rowGenerator.Items.FirstOrDefault(item => item.RowIndex == rowColumnIndex.RowIndex);
//Check whether the dataRow is null or not and the type as DataRow
if (dataRow != null && dataRow is DataRow)
{
//Get the column from the VisibleColumn collection based on the column index
var dataColumn = dataRow.VisibleColumns.FirstOrDefault(column => column.ColumnIndex == rowColumnIndex.ColumnIndex);
//Convert the input text to char type
char text;
char.TryParse(e.Text, out text);
//Skip if the column is not GridCurrencyColumn and the column is not already in editing
//Allow Editing only pressed letters digits and dot(.) sign key
if (dataColumn != null && (dataColumn.GridColumn is GridCurrencyColumn) && (e.Text.Equals(".") || char.IsLetterOrDigit(text)) && !dataColumn.IsEditing && SelectionController.CurrentCellManager.BeginEdit())
dataColumn.Renderer.PreviewTextInput(e);
}
base.OnTextInput(e);
}
} |
Sample Link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/GridCurrencyColumn-1420011604.zip
Please refer the below UG and Kb Link:
Regards,
Srinivasan
SI
Silvio
September 1, 2017 02:08 PM UTC
Thank you,
it's a good solution but it still does not completely resolve my question.
See attached video to better understand.
Ciao,
Silvio Scattaglia
Attachment: little_problem_with_dot_editing_currency_cells_5fe8b1f5.zip
MK
Muthukumar Kalyanasundaram
Syncfusion Team
September 4, 2017 07:17 PM UTC
Hi Silvio,
Thanks for the update.
We have checked your provided video file. On your attached video, currency column decimal separator showed as “,” instead of “.”. You can modify the condition by using this CurrencyDecimalSeparator property as like below code,
Code Snippet: C#
|
public class SfDataGridExt : SfDataGrid
{
public SfDataGridExt()
: base()
{
}
protected override void OnTextInput(TextCompositionEventArgs e)
{
if (!SelectionController.CurrentCellManager.HasCurrentCell)
{
base.OnTextInput(e);
return;
}
//Get the Current Row and Column index from the CurrentCellManager
var rowColumnIndex = SelectionController.CurrentCellManager.CurrentRowColumnIndex;
RowGenerator rowGenerator = this.RowGenerator;
//Get the row from the Row index
var dataRow = rowGenerator.Items.FirstOrDefault(item => item.RowIndex == rowColumnIndex.RowIndex);
//Check whether the dataRow is null or not and the type as DataRow
if (dataRow != null && dataRow is DataRow)
{
//Get the column from the VisibleColumn collection based on the column index
var dataColumn = dataRow.VisibleColumns.FirstOrDefault(column => column.ColumnIndex == rowColumnIndex.ColumnIndex);
//Convert the input text to char type
char text;
char.TryParse(e.Text, out text);
//Skip if the column is not GridCurrencyColumn and the column is not already in editing
//Allow Editing only pressed letters digits and dot(.) sign key
var decimalSeparator = (dataColumn.GridColumn as GridCurrencyColumn).CurrencyDecimalSeparator;
if (dataColumn != null && (dataColumn.GridColumn is GridCurrencyColumn) && (e.Text.Equals(decimalSeparator) || char.IsLetterOrDigit(text)) && !dataColumn.IsEditing && SelectionController.CurrentCellManager.BeginEdit())
dataColumn.Renderer.PreviewTextInput(e);
}
base.OnTextInput(e);
}
} |
Note:
|
You can must follow the key which has been used for the CurrencyDecimalSeparator to enter the edit-mode in application avoid usage of others. |
Please let us know if you have any query.
Regards,
SI
Silvio
September 5, 2017 10:28 AM UTC
Thank you for your help.
MK
Muthukumar Kalyanasundaram
Syncfusion Team
September 6, 2017 04:37 AM UTC
Hi Silvio,
Thanks for the update. Please let us know if you need any other assistance.
Regards,
Muthukumar K
MK
Muthukumar Kalyanasundaram
Syncfusion Team
September 6, 2017 04:37 AM UTC
Hi Silvio,
Thanks for the update. Please let us know if you need any other assistance.
Regards,
Muthukumar K
SIGN IN To post a reply.
- 6 Replies
- 3 Participants
-
SI Silvio
- Aug 31, 2017 02:33 PM UTC
- Sep 6, 2017 04:37 AM UTC