Declined
Last Updated: 21 Oct 2015 08:38 by ADMIN
ADMIN
Dimitar
Created on: 15 May 2014 11:12
Category: GridView
Type: Bug Report
0
FIX. RadGridView - RadDateTimeEditor when the user is entering value in the day field, the value is not replaced despite that it is selected(highlighted).
To reproduce:
- Add grid with a DateTime column with default value "5/1/2014";
- Start the app and press the following keys one after another: 5/1/
- You will notice that the "1" is not replaced.

Please note that the similar behavior occur when the year is entered (it does not match the default one). 

Workaround handle the key press for such cases manually:

void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    RadDateTimeEditor ed = e.ActiveEditor as RadDateTimeEditor;
    
    RadDateTimeEditorElement el = ed.EditorElement as RadDateTimeEditorElement;
    el.KeyPress += el_KeyPress;
}

private void el_KeyPress(object sender, KeyPressEventArgs e)
{
	RadDateTimeEditorElement el = (RadDateTimeEditorElement)sender;
	int day = el.Value.Value.Day;
	int key = -1;
	int.TryParse(e.KeyChar.ToString(), key);

	RadMaskedEditBoxElement element = el.TextBoxElement.TextBoxItem.Parent as RadMaskedEditBoxElement;
	MaskDateTimeProvider provider = element.Provider as MaskDateTimeProvider;

	if (provider.SelectedItemIndex == 2) {
		if (key > 0 & key <= 9) {
			if (el.TextBoxElement.TextBoxItem.SelectionLength != 0) {
				if (!booKeying) {
					dynamic NewValue = new DateTime(el.Value.Value.Year, el.Value.Value.Month, key);
					el.Value = NewValue;
					e.Handled = true;
					booKeying = true;
				}
			}
		}
	}
}
1 comment
ADMIN
Ivan Petrov
Posted on: 14 Oct 2015 12:58
The logic of the RadMaskedEditBox which is inside the DateTimeEditor is the following. When the user inputs a value the content of the current selection is shifted to the left and the user input is appended on the right. If the result is valid for the current field (day, month) the value is stored. If the new value is not valid the new user input is checked for validity on its own. If it is valid it is stored. If both above cases are not valid the selection is replaced with the minimum valid value.
Here are several examples which illustrate the above (selection is marked with [ ] and format is MM/dd/yyyy):

1. Editor content  [05]/01/2014
1.1. The user inputs 5
1.2. [05] is shifted left and user input is appended at right, the result is 55 which is not valid. 
1.3. Check if user input on its own is valid. 5 is valid so it replaces the selection.
1.4. The result is the same as the initial state.
1.5. Editor content [05]/01/2014

2. Editor content 05/[01]/2014
2.1. The user inputs 1
2.2. [01] is shifted left and user input is appended at right, the result is 11 which is valid and it replaces the selection.
2.3. Editor content 05/[11]/2014

3. Editor content 04/09/2014
3.1. The user inputs 0
3.2. [09] is shifted left and user input is appended at right, the result is 90 which is not valid. 
3.3. Check if user input on its own is valid. 0 is not valid so the selection is replaced with 01
3.4. Editor content 04/[01]/2014