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

IValueConverter gets wrong row

2 Answers 13 Views
GridView
This is a migrated thread and some comments may be shown as answers.
J
Top achievements
Rank 1
J asked on 14 Dec 2015, 08:39 AM

Hello,

 I use IValueConverter to calculate a column value based on other two column values. The problem is that when I edit the cell value and press Enter I get the next gridview row in IValueConverter. Do you know what the problem is? I use the code below on a UserControl.

 

this.clubsGrid.ItemsSource = EvolucionMercados.GetClubs();

public static IEnumerable<Club> GetClubs()
        {
            ObservableCollection<Club> clubs = new ObservableCollection<Club>();
            Club club;
 
            // Liverpool
            club = new Club("Liverpool", new DateTime(1892, 1, 1), 45362, 50.99f);
            club.Players.Add(new Player("Pepe Reina", 25, Position.GK, "Spain"));
            club.Players.Add(new Player("Jamie Carragher", 23, Position.DF, "England"));
            club.Players.Add(new Player("Steven Gerrard", 8, Position.MF, "England"));
            club.Players.Add(new Player("Fernando Torres", 9, Position.FW, "Spain"));
            clubs.Add(club);
 
            // Manchester Utd.
            club = new Club("Manchester Utd.", new DateTime(1878, 1, 1), 76212, 60.49f);
            club.Players.Add(new Player("Edwin van der Sar", 1, Position.GK, "Netherlands"));
            club.Players.Add(new Player("Rio Ferdinand", 5, Position.DF, "England"));
            club.Players.Add(new Player("Ryan Giggs", 11, Position.MF, "Wales"));
            club.Players.Add(new Player("Wayne Rooney", 10, Position.FW, "England"));
            clubs.Add(club);
 
            // Chelsea
            club = new Club("Chelsea", new DateTime(1905, 1, 1), 42055, 70.99f);
            club.Players.Add(new Player("Petr Čech", 1, Position.GK, "Czech Republic"));
            club.Players.Add(new Player("John Terry", 26, Position.DF, "England"));
            club.Players.Add(new Player("Frank Lampard", 8, Position.MF, "England"));
            club.Players.Add(new Player("Nicolas Anelka", 39, Position.FW, "France"));
            clubs.Add(club);
 
            // Arsenal
            club = new Club("Arsenal", new DateTime(1886, 1, 1), 60355, 35.19f);
            club.Players.Add(new Player("Manuel Almunia", 1, Position.GK, "Spain"));
            club.Players.Add(new Player("Gaël Clichy", 22, Position.DF, "France"));
            club.Players.Add(new Player("Cesc Fàbregas", 4, Position.MF, "Spain"));
            club.Players.Add(new Player("Robin van Persie", 11, Position.FW, "Netherlands"));
            clubs.Add(club);
 
            return clubs;
        }

<telerik:RadGridView
            Name="clubsGrid"
            Grid.Row="0"
            AutoGenerateColumns="False">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn
                    Header="Name"
                    DataMemberBinding="{Binding Name}">
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn
                    Header="Est."
                    DataMemberBinding="{Binding Established}"
                    DataFormatString="{}{0:yyyy}">
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn
                    Header="Stadium Capacity"
                    DataMemberBinding="{Binding StadiumCapacity}"
                    DataFormatString="{}{0:N0}">
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn
                    Header="Ticket Price"
                    DataMemberBinding="{Binding TicketPrice}"
                    DataFormatString="{}{0:C2}">
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn
                    Header="Sellout Revenue"
                    DataMemberBinding="{Binding Path=., Converter={StaticResource clubToSelloutRevenueConverter}}"
                    DataFormatString="{}{0:C2}">
                    </telerik:GridViewDataColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

2 Answers, 1 is accepted

Sort by
0
J
Top achievements
Rank 1
answered on 14 Dec 2015, 11:43 AM

You can check the issue in the demo projecto that I have uploaded to dropbox:

https://www.dropbox.com/s/yoe1ghe6lajlf02/calculatedCols.zip?dl=0

When you edit the column "Stadium Capacity" the field "Sellout Revenue" should be recalculated autommatically. I don't know what I'm doing wrong.

0
Stefan
Telerik team
answered on 16 Dec 2015, 03:59 PM
Hi Julio,

I tried reproducing the issue you are experiencing at your end, but to no avail. The value passed to the Convert() method of the IValueConverter was the one of the currently edited item of RadGridView. You can take a look at the following video as a demonstration: link. Can you please check it out and let me know in case I am missing something?

However, I am a little confused how would the value of the SelloutRevenue property would be updated based on the value of the StadiumCapacity one, as there is no logic implemented for updating it.
public int StadiumCapacity
{
    get { return this.stadiumCapacity; }
    set
    {
        if (value != this.stadiumCapacity)
        {
            this.stadiumCapacity = value;
            this.OnPropertyChanged("StadiumCapacity");
        }
    }
}

Regards,
Stefan X1
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
J
Top achievements
Rank 1
Answers by
J
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or