This is a migrated thread and some comments may be shown as answers.

EditTrigger - TextInput - how to make it work excel like

2 Answers 52 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Manohar
Top achievements
Rank 1
Manohar asked on 18 Apr 2011, 07:36 AM
Hi,
I use RadMaskedTextBox in CellEditTemplate and I would like to get Excel like behavior for a cell edit.

Having 'TextInput' as one of the EditTriggers, on pressing a key (text or number) the cell goes into edit mode.
Now, if I have selectAll for SelectionOnFocus, then all the digits/chars in that cell get selected and the second key (text or number) value
replaces the old value in the cell.

Whereas in Excel, the first key (test or number) input would replace the old value and let the user continue the edit.

For example, I have a value 700 and I intend to replace that value with 5000. So, to edit the cell with value 700 I press key 5, which should replace 700 and next two keys I will enter would be 0 and 0 and 0. The final new value will be 5000.

How to achieve this in GridView?

Thanks.
B.Manohar

2 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 21 Apr 2011, 08:27 AM
Hi Manohar,

Generally, my suggestions would be either to try to use a RadMaskedTextBox with MaskType - None, which probably will not be appropriate for your particular scenario or use the RadMaskedNumericInput. However, the latest will require handling the KeyDown event again. 
Nevertheless, based on the other thread on the same topic, I get the impression that you found a more appropriate solution for this scenario. So, in case you find it appropriate, please share it with the community. Thus everyone experiencing the very same issue will be able to benefit from your approach.
 

Best wishes,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Manohar
Top achievements
Rank 1
answered on 22 Apr 2011, 07:08 AM
Hi,
Here is what I have done for my requirement and it works. It can be enhanced to support more generic cases.

private void TreeListView_PreparedCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
{
    Dispatcher.BeginInvoke(new Action(() =>
    {
        RadMaskedTextBox maskedTextBox = e.EditingElement as RadMaskedTextBox;
        if (maskedTextBox != null)
        {
  
            System.Windows.Input.TextCompositionEventArgs textCompositionArgs = e.EditingEventArgs as System.Windows.Input.TextCompositionEventArgs;
  
            if (textCompositionArgs != null
                && !String.IsNullOrEmpty(textCompositionArgs.Text))
            {
                if (maskedTextBox.Mask.Equals("c", StringComparison.Ordinal)
                    || maskedTextBox.Mask.Equals("g", StringComparison.Ordinal))
                {
                    double inputValue;
  
                    bool isInputNumber = double.TryParse(textCompositionArgs.Text, out inputValue);
  
                    maskedTextBox.ClearValue(RadMaskedTextBox.MaskedTextProperty);
  
                    maskedTextBox.Value = inputValue;
  
                    maskedTextBox.SelectionStart = textCompositionArgs.Text.Length + 1;
                    maskedTextBox.SelectionLength = 0;
                }
                else if (maskedTextBox.Mask.Equals("p", StringComparison.Ordinal))
                {
                    maskedTextBox.SelectionStart = 0;
                    maskedTextBox.SelectionLength = maskedTextBox.MaskedText == null ? 0 : maskedTextBox.MaskedText.Length;
  
                    double inputValue;
  
                    bool isInputNumber = double.TryParse(textCompositionArgs.Text, out inputValue);
  
                    if (isInputNumber)
                    {
                        maskedTextBox.Value = inputValue * 0.01;
  
                        maskedTextBox.SelectionStart = textCompositionArgs.Text.Length;
                        maskedTextBox.SelectionLength = 0;
                    }
                }
            }
            else
            {
                maskedTextBox.SelectionStart = 0;
                maskedTextBox.SelectionLength = maskedTextBox.MaskedText == null ? 0 : maskedTextBox.MaskedText.Length;
            }
  
        }
    }));
}

Thanks.
B.Manohar
Tags
GridView
Asked by
Manohar
Top achievements
Rank 1
Answers by
Maya
Telerik team
Manohar
Top achievements
Rank 1
Share this question
or