RadNumericUpDown to Update a Second Column

8 posts, 0 answers
  1. todd
    todd avatar
    3 posts
    Member since:
    Aug 2010

    Posted 26 Aug 2010 Link to this post

    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?


  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 31 Aug 2010 Link to this post

    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
  3. DevCraft banner
  4. todd
    todd avatar
    3 posts
    Member since:
    Aug 2010

    Posted 31 Aug 2010 Link to this post

    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?
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 01 Sep 2010 Link to this post

    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
  6. todd
    todd avatar
    3 posts
    Member since:
    Aug 2010

    Posted 01 Sep 2010 Link to this post

    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
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 03 Sep 2010 Link to this post

    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
  8. John Davis
    John Davis avatar
    119 posts
    Member since:
    Apr 2007

    Posted 17 Jul 2012 Link to this post

    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.
  9. John Davis
    John Davis avatar
    119 posts
    Member since:
    Apr 2007

    Posted 17 Jul 2012 Link to this post

    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
            }
Back to Top
DevCraft banner