We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

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

Article ID: Published Date: Last Revised Date: Platform: Control:
675 04/30/2011 07/10/2014 Windows Forms GridDataBoundGrid(Classic)
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.