We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Editing does not start when typing "." character using GridCurrencyColumn column

Thread ID:

Created:

Updated:

Platform:

Replies:

132421 Aug 31,2017 02:33 PM UTC Sep 6,2017 04:37 AM UTC WPF 6
loading
Tags: SfDataGrid
Silvio
Asked On August 31, 2017 02:33 PM UTC

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

Srinivasan Vasu [Syncfusion]
Replied On 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); 
        } 
    } 
 
 
 
Please refer the below UG and Kb Link: 
 
 
 
Regards, 
Srinivasan 


Silvio
Replied On 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

Muthukumar Kalyanasundaram [Syncfusion]
Replied On 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, 
Muthukuamr K 


Silvio
Replied On September 5, 2017 10:28 AM UTC

Thank you for your help.


Muthukumar Kalyanasundaram [Syncfusion]
Replied On 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 


Muthukumar Kalyanasundaram [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;