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

RadNumericUpDown to Update a Second Column

7 Answers 128 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
todd
Top achievements
Rank 1
todd asked on 26 Aug 2010, 10:12 PM
I have a datastructure that looks like

candidate {
   score: int
   pct: float
}

and have bound a list of the candidate records to a RadGridView where two columns are as folllows:

<telerik:GridViewDataColumn Header="Score" IsFilterable="False"
                        DataMemberBinding="{Binding score, Mode=TwoWay}" Width="80" >
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding score}" HorizontalAlignment="Right"/>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate>
                            <telerik:RadNumericUpDown Loaded="Editor_Loaded" Maximum="10000" UpdateValueEvent="PropertyChanged"  IsInteger="True"  Minimum="0" ValueChanged="score_ValueChanged"
                                    Value="{Binding score, Mode=TwoWay, UpdateSourceTrigger=Explicit}" Width="60" O />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="Percent" IsReadOnly="True" IsFilterable="False" Width="70">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding percent}" HorizontalAlignment="Right"/>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>

and I would like to be able to (upon exiting the control) calculate the percentage scores for all rows in teh gridView and update them all.  Right now - the LostFocus event is not working.  I may have done something wrong on the .NET side as the ValueChanged event does not update the binding. 

Any thougts?


7 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 31 Aug 2010, 08:16 AM
Hi todd,

Please take a look at this blog post for a reference. The idea implemented in the sample project is that you bind the CalculatedColumn - in your case it would be the PercentColumn - to a property that exposes the calculated result of the previous two columns. Here the important thing is that you need to implement the INotifyPropertyChanged Interface so that whatever change occurs in the value of that certain property, it notifies for that modification.
Let me know if it corresponds to your requirements and expectations. 

Sincerely yours,
Maya
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
todd
Top achievements
Rank 1
answered on 31 Aug 2010, 06:13 PM
Thank you, I actually got to that point late last week. I am having trouble with the event model on the control now:

<telerik:GridViewDataColumn IsFilterable="False"
                        DataMemberBinding="{Binding scoreIdeas, Mode=TwoWay}" Width="80">
                    <telerik:GridViewDataColumn.Header>
                        <TextBlock Text="Ideas Score" TextWrapping="Wrap"  />
                    </telerik:GridViewDataColumn.Header>
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock   VerticalAlignment="Center" HorizontalAlignment="Right" Text="{Binding scoreIdeas}" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate>
                            <telerik:RadNumericUpDown Loaded="Editor_Loaded" Maximum="10000" UpdateValueEvent="PropertyChanged"  IsInteger="True"  Minimum="0"
                                    ValueChanged="score_ValueChanged" LostFocus="focusChg" GotFocus="focusChg"
                                    Value="{Binding scoreIdeas, Mode=TwoWay, UpdateSourceTrigger=Explicit}" Width="60" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>

I don't seem to be getting consistent calculation of the percentages, which is done in these handlers:
ValueChanged="score_ValueChanged" LostFocus="focusChg" GotFocus="focusChg"

I thought the ValueChanged handler should fire after every tick, (and it does) but the underlying recordset hasn't been updated yet.  It is tough to debug the Focus event handlers, however I often need to click into another field to trigger the update - which is strange...  It is almost as though the LostFOcus fires before the model is updated as well...  Workable for a prototype but not application quality.  ANy thoughts?
0
Maya
Telerik team
answered on 01 Sep 2010, 04:07 PM
Hi todd,

In order to provide you with a more appropriate solution, I would need more details about the purpose of using ValueChanged and LostForcus events. Are you trying to calculate the percent by handling them ? Is it not appropriate for your application to use the CellEditEnded event of the grid ?
Following up the idea implemented in the sample project in this blog post, isn't it applicable in your case to expose a new property directly containing the calculated percent value?

Regards,
Maya
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
todd
Top achievements
Rank 1
answered on 01 Sep 2010, 07:15 PM
I think perhaps the CellEditEnded event might be good way as a catch all.  But I would like to recalculate the percentages on the fly after every tick of the RadNumericUpDown control.  The poperty for the percent triggers the INotifyPropertyChanged. 

An Observation is the record field underlying the RadNumericUpDown control doesn't appear to change when the control is being chnaged.  So that might be an issue.

AN example of the functionality is:


Name        Score        Percent
Joe                   2                 40
Tim                    1                20
Andrew            2                40

Then as I click Tim Down, while the conrtol is still editable, I recalc the percentages across the board in realtime:

Name        Score        Percent
Joe                    2                 50
Tim                    0                0
Andrew              2                50
0
Maya
Telerik team
answered on 03 Sep 2010, 10:08 AM
Hi todd,

You may try to handle the ValueChanged event of the RadNumericUpDown and use the NewValue property:

private void RadNumericUpDown_ValueChanged(object sender, RadRangeBaseValueChangedEventArgs e)
        {                                  
            MessageBox.Show("CurrentValue is: " + e.NewValue);
        }
 
You make take a look at our online documentation for additional information about handling events of the RadNumericUpDown.

Sincerely yours,
Maya
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
John Davis
Top achievements
Rank 2
answered on 17 Jul 2012, 07:27 PM
I need to get new values entered in grid cells (RadNumericUpDown) and then update the database record corresponding to the rows having values changed. I have not found an example in Telerik documentation.  I did find one way to get the new value entered in a cell:

private void RadNumericUpDown_ValueChanged(object sender, RadRangeBaseValueChangedEventArgs e)
        {                                  
            MessageBox.Show("CurrentValue is: " + e.NewValue);
        }

but I also need to know the value of the identifier of the database record associated with this row. Otherwise I don't know in which row this new value occurred.  How can I get it?

The datasource for the grid is a database view, rather than a view model. Therefore I am having trouble if I set up two way binding. Instead, I could put the identifier of the database record in a column of the grid. This technique could work if I can find out the value in this column for the row in which the user entered a new value into the RadNumericUpDown.
0
John Davis
Top achievements
Rank 2
answered on 17 Jul 2012, 08:46 PM
Solved.

 private void btnPgcLbqValueChanged(object sender, RadRangeBaseValueChangedEventArgs e)
        {

            var NewValue = e.NewValue;
            var OldValue = e.OldValue;
            var Row = (vScsProcGroupAllSc)this.PgcGrid.Items.CurrentItem;

//vScsProcGroupAllSc is the database view that is the data source
//Row has all the values for the record associated with the row in which the user changed a value
//Knowing NewValue and Row values I have everything I need to update the database
        }
Tags
NumericUpDown
Asked by
todd
Top achievements
Rank 1
Answers by
Maya
Telerik team
todd
Top achievements
Rank 1
John Davis
Top achievements
Rank 2
Share this question
or