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

Calculate one GgridView cell out of two

7 Answers 73 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Uwe
Top achievements
Rank 1
Uwe asked on 05 Nov 2012, 11:15 AM
Hello, can anyone give me a hint what is the best way to calculate one cell, which is read only, from two others cells which are changeable in a GgridView.
Intuitive I would take the CellEditEnded event, but maybe there is a smarter way? 
Thank you in advance Uwe

7 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 05 Nov 2012, 11:26 AM
Hello,

You could use a CellStyleSelector for that column and return a ReadOnly Style if the conditions based on the other two columns are met.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Uwe
Top achievements
Rank 1
answered on 27 Nov 2012, 03:07 PM
Hello Didie, thank you for your hint, the animated cells in the example is an interesting 
technique, which I will use, but it does not solve my current problem. My GridView is bind 
to an QueryableEntityCollectionView and I have 3 columns: ShippingWeight, GrossWeightTruck 
and NetWeightTruck. ShippingWeight is read only. The user should edit GrossWeightTruck and 
NetWeightTruck and ShippingWeight should be calculated. I am using MVVM Light to fetch the 
CellEditEnded Event:

<telerik:RadGridView Name="xGridView" Margin="29,89,38,105" Grid.ColumnSpan="2" ItemsSource="{Binding BAMeasurements}" IsEnabled="{Binding IsChecked, ElementName=UnLock, Mode=TwoWay}" ScrollMode="RealTime" DataLoadMode="Asynchronous" AutoGenerateColumns="False">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="CellEditEnded" >
            <commands:EventToCommand Command="{Binding CellEditEnded}" PassEventArgsToCommand="True"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
 
...


My problem is to find out which cell is send the event and how do I get the ShippingWeight cell of 
the right row?

Greetings Uwe

0
Dimitrina
Telerik team
answered on 27 Nov 2012, 03:32 PM
Hello Uwe,

You could follow this help article where you will find another way to select the appropriate Style. When the SelectStyle method is invoked you have the item (which is the one from the right row) and you could check the property you are interested in. 

Please try this and let me know if you have any further questions.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Uwe
Top achievements
Rank 1
answered on 27 Nov 2012, 03:42 PM
... ok to get the cell which fires the event.
I found out this:

private void CellEditEndedToCommandF(object obj)
{
    GridViewCellEditEndedEventArgs GridEventArg = (GridViewCellEditEndedEventArgs)obj;
    GridViewColumn Colum = GridEventArg.Cell.Column;
    string ColumUniqueName = Colum.UniqueName;
    switch (ColumUniqueName)
    {
        case "ShippingWeight":
            ...
            break;
        case "GrossWeightTruck":
            ...
            break;
        case "NetWeightTruck":
            ...
            break;
    }
}

... but I'm still looking for the index of the row or something that.

Best Regards


0
Uwe
Top achievements
Rank 1
answered on 27 Nov 2012, 05:18 PM
Hello Didie,

I understand your approach, but when I do this:

/// <summary>
/// CLASS ShippingWeightStyle
/// </summary>
public class ShippingWeightStyle : StyleSelector
{
    public override Style SelectStyle(object item, DependencyObject container)
    {
        if (item is BAMeasurement)
        {
            BAMeasurement bam = item as BAMeasurement;
            bam.ShippingWeight = bam.GrossWeightTruck - bam.NetWeightTruck;
            Debug.WriteLine("RECUSION!!!");
        }
        return null;
    }
}


I get a  recursion....
0
Uwe
Top achievements
Rank 1
answered on 27 Nov 2012, 05:37 PM
I can prevent this with a global variable, but is it a good idea?
0
Dimitrina
Telerik team
answered on 29 Nov 2012, 12:16 PM
Hello Uwe,

I am afraid that I pointed you into a wrong direction. I thought that you would like to set some cells to be ReadOnly and others not. Please excuse me for misleading you. 

In order to calculate the values in one column based on the values in two others, I would suggest you to check the "Calculated Column" WPF Demo. 

Please check it and let me know if you have any further questions.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Uwe
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Uwe
Top achievements
Rank 1
Share this question
or