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
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.
Maya
the Telerik team
<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?
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?
Maya
the Telerik team
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
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
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.
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
}