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. Image for the cookie policy date
close icon

calculation of a cell value in Griddataboundgrid cell

Hi, I am using Griddataboundgrid, user can enter numericals in cells of a perticular column. if user enters (2*4)/4 in a cell, as soon as the focus goes out of the cell, the cell should show a value as 2. user can enter any format with numericals. will the formula cell type works for a griddataboundgrid? ---seash

7 Replies

AD Administrator Syncfusion Team August 13, 2004 05:35 AM UTC

You have to do addition work to get a formula cell to work in a GridDataBoundGrid. 1) Create some kind of data store (ArrayList or hashtable or ???) that has space for a GridFormulaTag object for each cell that you want to be a formula 2) Subscribe to grid.Model.QueryCellInfo. There, if e.RowIndex and e.ColIndex point to a formula cell, set e.Style.FormulaTag to be its formulatag from your data store. 3) Subscribe to grid.model.SaveCellInfo. There if e.RowIndex and e.COlIndex point to a formula cell, save e.Style.FormulaTag into your data store for that row and column. Here is a link to a KB on this task. http://www.syncfusion.com/Support/article.aspx?id=10439 One last comment is that the default behavior is to require your user to type = 5*2+3 and not just type 5*2+3 . If you don''t want to require the equal sign, then you have to create an new instance of teh GridFormulaCellModel registering that with the grid.CellModels to be a ''custom'' celltype. There is a contructor overload that lets you set the GridFormulaCellModel.formulaChar value to the empty string with code like. You would then use a CellTtype of MyFormulaCell instead of FormulaCell. this.gridControl1.CellModels.Add("MyFormulaCell", new GridFormulaCellModel(this.gridControl1.Model, ''\0''));


AK Anil Kumar M August 13, 2004 06:13 AM UTC

Hi Burch, Thanks for your reply, I think you didnt get me right, may be i ddint explain well. I want each cell to behave like a calculator, ''cause i never no how user enters values into a cell for example: 1> 2*3*8*6*4*9*7...... 2> (2*3)+2*9/4 3> 3-4+1/4*(2*3) etc..... so i cant store arraylist or hashtable all the desired formats a user can enter in a cell.. even i dont know what type of numericals(in a formula type) he may enter. Can i get integer values in above type from the cell value? like (2*3)/4+3-4 including the open and close brackets so that i get the calculated value in my program and feed the result back to the cell itself ---seash >You have to do addition work to get a formula cell to work in a GridDataBoundGrid. > >1) Create some kind of data store (ArrayList or hashtable or ???) that has space for a GridFormulaTag object for each cell that you want to be a formula > >2) Subscribe to grid.Model.QueryCellInfo. There, if e.RowIndex and e.ColIndex point to a formula cell, set e.Style.FormulaTag to be its formulatag from your data store. > >3) Subscribe to grid.model.SaveCellInfo. There if e.RowIndex and e.COlIndex point to a formula cell, save e.Style.FormulaTag into your data store for that row and column. > >Here is a link to a KB on this task. > >http://www.syncfusion.com/Support/article.aspx?id=10439 > >One last comment is that the default behavior is to require your user to type = 5*2+3 and not just type 5*2+3 . If you don''t want to require the equal sign, then you have to create an new instance of teh GridFormulaCellModel registering that with the grid.CellModels to be a ''custom'' celltype. There is a contructor overload that lets you set the GridFormulaCellModel.formulaChar value to the empty string with code like. You would then use a CellTtype of MyFormulaCell instead of FormulaCell. > >this.gridControl1.CellModels.Add("MyFormulaCell", new GridFormulaCellModel(this.gridControl1.Model, ''\0'')); >


AD Administrator Syncfusion Team August 13, 2004 07:36 AM UTC

I don''t think I misunderstood your question. Here is a sample that implements both the technique I suggested plus another one. The suggested technique allows the grid to remomber the entered expression so the user can edit it later. If you do not need this editing capability, and just want the grid to remember the computed value, then things are simpler. You can handle the CurrentCellValidating event, and call on the formula engine to compute the expression and swap the computed value for the entered formula at that point. GDBCFormulaColumn_2207.zip


AK Anil Kumar M August 13, 2004 08:30 AM UTC

Hi Burch, Thanks for your help. But there is an error i am getting when i type 2*3 or any thing in the cell, the error is "2*3 is not a valid value for Decimal", since my grid is griddataboundgrid and the database values for that perticular column is of type Decimal. is it the reason behind the error? ---seash


AD Administrator Syncfusion Team August 13, 2004 08:51 AM UTC

You do not see this problem in the sample that I included, do you? Do not set the style.CellValueType for the column to double or decimal. Formula cells must be string as you are typing a string into the cell.


AK Anil Kumar M August 13, 2004 09:24 AM UTC

Yes, there is no problem with your sample. In my applicayion I am neither setting style.CellValueType to Decimal. My application database column is of type Decimal. I am still having the same problem with that column, where as other colums which are string typr in database are working fine when i made them formula cells ---seash


AD Administrator Syncfusion Team August 13, 2004 09:38 AM UTC

Try setting the GridBoundColumn.StyleInfo.CellValueType to string. So, if you have not explicitly added GridBoundColumns, try code like: this.grid.Binder.InternalColumns["MyColumnName"].StyleInfo.CellValueType = type of(string);

Loader.
Live Chat Icon For mobile
Up arrow icon