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

RowEditEnded Event fires with Validation errors

6 Answers 234 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Missing User
Missing User asked on 16 Nov 2011, 06:19 PM
Hello.

I have a Editable RadGridView, in the RowValidating event I use some logic to implement validation on the row that is about to commit.
But I'm facing some strange behavior, even if i set e.IsValid = false in the RowValidating event it still fire's the RowEditEnded and the row is commited with fields in blank.

As you say in the documentation:
The RowEditEnded event occurs when row validation passed successfully and new data is committed to the RadGridView.ItemsSource.

I thought if I set the IsValid property to false, the RowEditEnded will not be fired untill the validation occurs but it's not what is happening. Am I missing something here?

I'll share some code:

RowValidating Event

private void GridViewSegmentos_RowValidating(object sender, GridViewRowValidatingEventArgs e)
{
    People p = e.Row.DataContext as People;
 
    if (p.Age == null)
    {
        e.IsValid = false;
    }
    if (p.Address == null)
    {
        e.IsValid = false;
    }
    if (!e.IsValid)
    {
        MessageBox.Show("All fields are required.");
    }
}

RowEditEnded

private void GridViewSegmentos_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
{
    People p = new People();
    p = e.Row.DataContext as People;
  
    this.GridViewSegmentos.Columns[5].IsVisible = true;
 
    else if (e.EditOperationType == GridViewEditOperationType.Insert)
    {
     
this.ViewModel.AtualizaPessoaNegocioSegmento(p);
    }
    else if (e.EditOperationType == GridViewEditOperationType.Edit)
    {
         this
.ViewModel.AtualizaPessoaNegocioSegmento(p);
    }
}

Obs: I'm using the latest version of the controls.
Thank you.

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 17 Nov 2011, 10:41 AM
Hi Joao Paulo Grassi,

I have tried to reproduce the scenario you described, but still without any success. Could you take a look at the sample attached to verify whether you can get the same behavior on it ? 

 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Missing User
answered on 17 Nov 2011, 11:51 AM
Hi Maya.

Thanks for your help, I look more into my code and I found a place that I call the CancelEdit method, because of this the RowEditEnded is firing. Now i fix it but another problem show, in my GridView i have 3 columns the second one is a Column with a RadComboBox inside of it, the last one is a number column.

When the user insert a new row on the gridview he need to fill all the fields. If the user fill the thirty column with some value and try to select some item in the combobox the RowValidating starts, and of course the combo doesn't have a value selected yet so the row is marked as red but the combobox dissapear, if i click in the thirty cell again then the combo shows again.

I will attach some images to show you.

Is there a way to move the focus of the cursor to the next column, if the validation fails in the combobox column?

Thanks again!
0
Maya
Telerik team
answered on 17 Nov 2011, 02:01 PM
Hello Joao Paulo Grassi,

Would you provide a bit more information about how do you define your columns ? Generally, any relevant code-snippet would be helpful.


Best wishes,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Missing User
answered on 17 Nov 2011, 02:22 PM
Hello, sure:

<telerik:RadGridView x:Name="GridViewSegmentos"
                     AutoGenerateColumns="False"
                     Grid.Row="2"
                     Grid.Column="0"
                     ShowGroupPanel="False"
                     HorizontalAlignment="Left"
                     Loaded="GridViewSegmentos_Loaded"
                     ShowInsertRow="True"
                     PreparingCellForEdit="GridViewSegmentos_PreparingCellForEdit"
                     RowValidating="GridViewSegmentos_RowValidating"
                     CellValidating="GridViewSegmentos_CellValidating"
                     Margin="5,10,5,15"
                     AddingNewDataItem="GridViewSegmentos_AddingNewDataItem"
                     RowEditEnded="GridViewSegmentos_RowEditEnded"
                     telerik:StyleManager.Theme="Office_Silver"
                     Grid.ColumnSpan="2">
 
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="PessoaNegocioSegmento"
                                    DataMemberBinding="{Binding PessoaNegocioSegmentoID}"
                                    IsVisible="False" />
 
        <telerik:GridViewDataColumn Header="PessoaNegocioPeriodoID"
                                    DataMemberBinding="{Binding PessoaNegocioPeriodoID}"
                                    IsVisible="False" />
 
 
        <telerik:GridViewDataColumn IsVisible="True">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <telerik:RadButton x:Name="btnHabilitarEdicao"
                                       Content="Editar"
                                       IsEnabled="True"
                                       telerik:StyleManager.Theme="Office_Silver"
                                       Click="btnHabilitarEdicao_Click" />
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
        <telerik:GridViewDataColumn Header="Segmento"
                                    x:Name="Segmento"
                                    UniqueName="Segmento">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <telerik:RadComboBox x:Name="cmbSegmentos"
                                         Loaded="cmbSegmentos_Loaded"
                                         telerik:StyleManager.Theme="Office_Silver"
                                         Width="100" />
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
 
        <telerik:GridViewDataColumn Header="Valor Custo"
                                    x:Name="ValorCusto"
                                    UniqueName="ValorCusto"
                                    DataMemberBinding="{Binding ValorCusto, ConverterCulture=pt-BR, StringFormat=\{0:n2\}}" />
 
        <telerik:GridViewDataColumn>
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <telerik:RadButton x:Name="btnExcluirGrid"
                                       Content="Excluir"
                                       telerik:StyleManager.Theme="Office_Silver"
                                       Loaded="btnExcluirGrid_Loaded"
                                       Click="btnExcluirGrid_Click" />
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
 
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

What's happening is, everytime that I click on the RadComboBox in the Segmento column the row is "commited" because the RowValidating event is fired, and the row becomes "invalid" but the user doesn't choose a item yet.
What I REALY need to do is, not commit the row untill the user imput a value in the ValorCusto column and select a Item in the ComboBox on the Segmento column.
0
Missing User
answered on 17 Nov 2011, 02:50 PM
Hello again,

I manage to correct the problem, i set both first and second columns that contains a RadButton and a ComboBox inside a CellTemplate to ReadOnly="True"
now when the validation occurs, these columns don't get "focused" and the controls don't dissapear because they are ReadOnly. This fix my problems perfectly. Maybe you can explain this in the documentation I think that will be helpful for others people.

Thank you for your help.
0
Accepted
Maya
Telerik team
answered on 18 Nov 2011, 10:49 AM
Hi Joao Paulo Grassi,

I am glad to see that you managed to resolve the issue in the most appropriate for your scenario way. Thank you for sharing your approach with the community.
 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Missing User
Answers by
Maya
Telerik team
Missing User
Share this question
or