Hello Telerik,
I'm working with a RadGridView in WPF, and actually, I'm testing for the cells editing.
When the user pressed 'Enter' to validate his data, the focus is automaticaly did on the next row. I searched in your Controls Examples but I didn't found the solution.
=> How can I to do that the focus should do on the cell was been edited ?
Thank you very much.
Valentin.
10 Answers, 1 is accepted
Hello,
I have 2 others questions about RadGridView (I can't update the post title) :
1- It's possible for a grid to set ActionOnLostFocus="CancelEdit". But if the user is editing a cell and he clicks on an other cell, the thread goes to _CellValidating event (where I check the correct format of cells user values) and he returns an error. I want to know if is it possible to set an 'ActionOnLostFocus' for a cell ?
(Exemple width attached 'actiononlostfocus' file)
2- I created a Style for gridView cells :
<Style x:Key=
"cellStyle"
TargetType=
"telerik:GridViewCell"
>
<Setter Property=
"HorizontalContentAlignment"
Value=
"Center"
/>
</Style>
When I applied it on my gridColumns, the TextBox (or Textblock) width is set to Auto and I didn't found where can I fix it to the column width.
(Exemple width attached 'witdh_1' & 'width_2' files)
Can you help me ?
Thank you.
Currently ActionOnLostFocus is supported only on Row and GridView level and not for separate cells only. As for modifying the default navigation behavior after completing edit, you can define a custom CommandsProvider that controls the logic that is executed on "enter".
As for the inquiry about the CellStyle, can you please confirm what the desired results would be? Stretched textblock/textbox with centered text, am I right?
Regards,
Ivan Ivanov
Telerik by Progress
Hello Ivan,
Thank you for your answer.
Yes, the goal is diplaying stretched textblock/textbox with centered text and unresizable textblock/textbox.
Actually, when the cell is in editing mode, and my custom style is applied, the textblock/textbox width is automaticly adjusted.
And, do you have any idea for the first question ?
Thank you very much.
Valentin.
Sorry, the answer for the first question is in your answer !
So, I don't know how can I apply an override method for a 'ActionOnLostFocus' cell with the CustomKeybordCommandProvider ?
Thank you.
You want to prevent RadGridView from starting edit of next row, when "Enter" is hit, am I right? The command provider mechanism of RadGridView enqueues a sequence of commands that should be executed when the appropriate keyboard input occurs. The default sequence when enter is hit contains the MoveNext command, which you can skip, preventing the focus to move the first editable cell of the next row. However, I am not entirely sure whether you target to cancel the edit if there are validation errors?
As for the text alignment question, you can use the TextAlignment property of GridViewBoundColumnBase, setting it to 'center'. I believe that it should do the trick, without the need of having custom styles.
Regards,
Ivan Ivanov
Telerik by Progress
Hello Ivan,
I found the solution for the 'Enter' key pressed with command provider like you told me. But, I don't know how use the KeybordCommandProvider for 'ActionOnLostFocus' with Mouse ?
Next, TextAlignment="Center" for each telerik:GridViewDataColumn is working find !
Thank you.
Valentin.
You can try calling CancelEdit on CellValidated, to mimic ActionOnLostFocus="CancelEdit", on cell level. It should be something like this:
private void OnCellValidated(object sender, GridViewCellValidatedEventArgs e)
{
if (e.ValidationResult.ErrorMessage != null)
{
clubsGrid.CancelEdit();
}
}
Regards,
Ivan Ivanov
Telerik by Progress
Hello,
Thanks for you'r help but the process doesn't enter in my gridViewVariables_CellValidated and so it doesn't working find.
I tried to set a custom Cell.LostFocus Event like this :
private
void
gridViewSystemesDeCollectes_CellLoaded(
object
sender, CellEventArgs e)
{
if
(e.Cell
is
GridViewCell)
e.Cell.LostFocus +=
new
RoutedEventHandler(
this
.OnCellLostFocus);
}
private
void
OnCellLostFocus(
object
sender, RoutedEventArgs e)
{
GridViewCell cell = sender
as
GridViewCell;
if
(cell !=
null
)
cell.IsInEditMode =
false
;
}
But IsInEditMode Cell Property is not the find property to CancelEditMode.
Valentin.
If you plan to stick with this approach, you can use the RowInEditMode property to check whether the target cell is a child of the edited row:
void OnCellLoaded(object sender, Telerik.Windows.Controls.GridView.CellEventArgs e)
{
. . .
if (e.Cell.ParentRow == gridView.RowInEditMode)
{
gridView.CancelEdit();
}
}
Regards,
Ivan Ivanov
Telerik by Progress