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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

QueryCellFormattedtext and SaveCellFormattedText

Platform: WinForms |
Control: GridDataBoundGrid(Classic) |
Published Date: April 30, 2011 |
Last Revised Date: July 10, 2014

 

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon 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.Close Icon