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

Block return next row after cell editing

10 Answers 313 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Valentin
Top achievements
Rank 1
Iron
Iron
Valentin asked on 12 Dec 2016, 08:59 AM

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

Sort by
0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 13 Dec 2016, 08:38 AM

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.

0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 28 Dec 2016, 02:24 PM
Up :)
0
Ivan Ivanov
Telerik team
answered on 30 Dec 2016, 11:13 AM
Hello,

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
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 30 Dec 2016, 12:58 PM

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.

0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 30 Dec 2016, 02:59 PM

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.

0
Ivan Ivanov
Telerik team
answered on 30 Dec 2016, 03:24 PM
Hi,

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
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 02 Jan 2017, 08:18 AM

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.

 

0
Ivan Ivanov
Telerik team
answered on 02 Jan 2017, 03:49 PM
Hi,

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
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 03 Jan 2017, 09:14 AM

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.

0
Ivan Ivanov
Telerik team
answered on 06 Jan 2017, 07:41 AM
Hello,

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
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Valentin
Top achievements
Rank 1
Iron
Iron
Answers by
Valentin
Top achievements
Rank 1
Iron
Iron
Ivan Ivanov
Telerik team
Share this question
or