QueryCellFormattedtext and SaveCellFormattedText
The sample converts the Total mark which, is present in the database to Percentage with the help of a button click . Again it converts the percentage to Total Marks while saving the data from the grid , back to the database.
The sample contains two grids. The purpose of the second grid is to allow you to verify as to whether the data is being saved as Total Marks and not by percentage since percentage is just for display purposes.
The purpose of the QueryCellFormattedText is to take the data which, is present in the Total Marks and convert it to Percentage for display. The SaveCellFormattedText is to take the units that are entered by the user in Percentage, and convert them to Total Marks so that they can be saved as Total Marks
C#
private void Model_QueryCellFormattedText(object sender, Syncfusion.Windows.Forms.Grid.GridCellTextEventArgs e)
{
if(e.Style.CellValueType==typeof(double) && e.Style.Text.Length > 0)
{
double dVal = (double)e.Style.CellValue/500 *100;
e.Text = dVal.ToString("##.##");
e.Handled = true;
}
}
private void Model_SaveCellFormattedText(object sender, Syncfusion.Windows.Forms.Grid.GridCellTextEventArgs e)
{
if(e.Style.CellValueType==typeof(double) && e.Style.Text.Length > 0)
{
double dVal = double.Parse(e.Text)/100 *500;
e.Style.CellValue = dVal;
e.Handled = true;
}
}
VB
Private Sub Model_QueryCellFormattedText(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCellTextEventArgs)
If e.Style.CellValueType Is GetType(Double) AndAlso e.Style.Text.Length > 0 Then
Dim dVal As Double = CDbl(e.Style.CellValue)/500 *100
e.Text = dVal.ToString("##.##")
e.Handled = True
End If
End Sub
Private Sub Model_SaveCellFormattedText(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCellTextEventArgs)
If e.Style.CellValueType Is GetType(Double) AndAlso e.Style.Text.Length > 0 Then
Dim dVal As Double = Double.Parse(e.Text)/100 *500
e.Style.CellValue = dVal
e.Handled = True
End If
End Sub
Here is a sample that illustrates this:
http://websamples.syncfusion.com/samples/KB/Grid.Windows/QueryAndSaveCellFormattedText/main.htm