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

Strange Environment After Add New Row

2 Answers 66 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dario Concilio
Top achievements
Rank 2
Dario Concilio asked on 20 Feb 2017, 01:22 PM

Hi to all,

I have a simple grid, that I'm using with MVVM pattern.

<Style x:Key="ListEditableFlatStyle" TargetType="telerik:RadGridView" BasedOn="{StaticResource RadGridViewStyle}">
    <Setter Property="CanUserDeleteRows" Value="True"/>
    <Setter Property="CanUserFreezeColumns" Value="True"/>
    <Setter Property="CanUserInsertRows" Value="True"/>
    <Setter Property="CanUserReorderColumns" Value="False"/>
    <Setter Property="CanUserResizeColumns" Value="True"/>
    <Setter Property="CanUserResizeRows" Value="False"/>
    <Setter Property="CanUserSelect" Value="True"/>
    <Setter Property="CanUserSortColumns" Value="False"/>
    <Setter Property="CanUserSortGroups" Value="False"/>
    <Setter Property="ShowGroupPanel" Value="False"/>
    <Setter Property="ShowSearchPanel" Value="False"/>
    <Setter Property="AutoGenerateColumns" Value="False"/>
    <Setter Property="IsReadOnly" Value="False"/>
    <Setter Property="SelectionMode" Value="Extended"/>
    <Setter Property="SelectionUnit" Value="FullRow"/>
    <Setter Property="IsLocalizationLanguageRespected" Value="False"/>
    <Setter Property="Margin" Value="2"/>
    <Setter Property="NewRowPosition" Value="Bottom"/>
    <Setter Property="GroupRenderMode" Value="Flat"/>
</Style>
 
<telerik:RadGridView ItemsSource="{Binding MisureModelli}" Style="{StaticResource ListEditableFlatStyle}"
                     GroupRenderMode="Flat"
                     Grid.Row="6" Grid.ColumnSpan="4">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding PesoLordo, StringFormat=\{0:N2\}}" Header="Peso Lordo (Kg)" HeaderTextAlignment="Right"
                        TextAlignment="Right"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding PesoNetto, StringFormat=\{0:N2\}}" Header="Peso Netto (Kg)" HeaderTextAlignment="Right"
                        TextAlignment="Right"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Volume, StringFormat=\{0:N3\}}" Header="Volume (m³)" HeaderTextAlignment="Right"
                        TextAlignment="Right" IsReadOnly="True"/>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

 

When I click "new row", it disappears exists row, I don't undestrand why.

2 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 23 Feb 2017, 09:54 AM
Hello,

I've tried to reproduce the issue you've described based on the provided information, but was, unfortunately, unable to do so. I'm attaching a sample project to demonstrate my approach.

Could you please have a look at it and let me know whether I'm missing something of importance and what modifications I should make in order to replicate it at my end as well?

Thank you in advance for your cooperation on the matter.

Regards,
Dilyan Traykov
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 you to write beautiful native mobile apps using a single shared C# codebase.
0
Dario Concilio
Top achievements
Rank 2
answered on 23 Feb 2017, 10:11 AM

I found the problem, I've wrong overring of Equals and GetHashCode of model, the primary key of model consists of two fields, and not one.

01.//WRONG OVERRIDES
02.public override bool Equals(object obj)
03.{
04.    var other = obj as MisuraModelloModel;
05.    return other != null && other.CodiceModelloCommerciale == this.CodiceModelloCommerciale;
06.}
07. 
08.public override int GetHashCode()
09.{
10.    if (CodiceModelloCommerciale != null)
11.        return CodiceModelloCommerciale.GetHashCode();
12.    else
13.        return -1;
14.}
15. 
16.//CORRECT OVERRIDES
17.public override bool Equals(object obj)
18.{
19.    var other = obj as MisuraModelloModel;
20.    return other != null &&
21.           ((other.CodiceModelloCommerciale == this.CodiceModelloCommerciale) &&
22.            (other.NumeroCollo == this.NumeroCollo));
23.}
24. 
25.public override int GetHashCode()
26.{
27.    if (CodiceModelloCommerciale != null)
28.        return $"{CodiceModelloCommerciale}.{NumeroCollo}".GetHashCode();
29.    else
30.        return -1;
31.}
Tags
GridView
Asked by
Dario Concilio
Top achievements
Rank 2
Answers by
Dilyan Traykov
Telerik team
Dario Concilio
Top achievements
Rank 2
Share this question
or