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.

Formula in databound grid

Thread ID:

Created:

Updated:

Platform:

Replies:

28519 May 3,2005 04:45 PM May 4,2005 11:18 AM Windows Forms 6
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On May 3, 2005 04:45 PM

Hi I have a databound grid which I has a total column which I want have a formula in it. I have followed the example in the knowledge base and created the GridQueryCellInfo and GridSaveCellInfo sub routines. The problem is that when I start with a blank grid and add a new line, the formula is not automatically populated, nor is it populated after save that line. The formula only shows after I have added a second line i.e the last line is always blank This is the sub that I have if anyone can see what I am doing wrong, I''d be greatful as I have been looking at this for far too long. Private Sub GridQueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs) If e.ColIndex = 15 AndAlso e.RowIndex > 0 AndAlso e.RowIndex <= dsFEE_ui.Tables(0).Rows.Count Then e.Style.CellType = "FormulaCell" e.Style.Text = String.Format("=SUM({0}{1}:{2}{1})", GridRangeInfo.GetAlphaLabel(3), GridRangeInfo.GetNumericLabel(e.RowIndex), GridRangeInfo.GetAlphaLabel(14)) e.Style.FormulaTag = CType(Me.FeeformulaTags((e.RowIndex - 1)), GridFormulaTag) e.Handled = True End If End Sub

Administrator [Syncfusion]
Replied On May 3, 2005 06:28 PM

Just someting quick to try. Try setting this property to see if that will handle this problem. grid.Model.Options.RefreshCurrentCellBehavior = GridRefreshCurrentCellBehavior.RefreshRow Are there any exceptions being shown in your output window when you run this code? Do you have some mechanism to increase the size of Me.FeeFormulaTags when you add a new row?

Administrator [Syncfusion]
Replied On May 4, 2005 04:22 AM

Depending on where you put that line then yes and no. If you put it in the GridQueryCellInfo, there were output errors galore System.InvalidOperationException: Recursive call detected. When accessing grid cell objects from a QueryCellInfo event handler make sure you do not recursively access the same cell. If I put it just after I bind the dataset, then no errors but didn''t fix the issue. I don''t have a mechanisim to increase the size of the formula tags on adding a new row. Where would I go to do that?

Administrator [Syncfusion]
Replied On May 4, 2005 07:35 AM

If you are adding a new row, say your datatable goes for 0 datarows to 1 datarow, you will need one extra spot in your Me.FeeformulaTags to hold the tag from the new row. Each time you add a row, you will have to increase the capacity of Me.FeeformulaTags by one. You would do this in SaveCellInfo before you save the e.Style.FormulaTag. You can check for me.grid.Binder.IsAddNew = true in SaveCellInfo. If so, then you would add to Me.FeeformulaTags so it can hold the extra formulatag.

Administrator [Syncfusion]
Replied On May 4, 2005 09:08 AM

Hi Clay I think this is what you are meaning. This is the sub which handles the SaveCellInfo event Private Sub GridSaveCellInfo(ByVal sender As Object, ByVal e As GridSaveCellInfoEventArgs) If e.ColIndex = 15 AndAlso e.RowIndex > 0 AndAlso e.RowIndex <= dsFEE_ui.Tables(0).Rows.Count Then FeeformulaTags((e.RowIndex - 1)) = e.Style.FormulaTag e.Handled = True End If End Sub As far as I can tell, should be working....

Administrator [Syncfusion]
Replied On May 4, 2005 10:23 AM

My point was that everytime you add a row, dsFEE_ui.Tables(0).Rows.Count gets bigger. So, does FeeformulaTags ''grow'' somehow to save the tags for the new row. What is FeeformulaTags? Is it an arraylist or hashtable that can grow? If so, where do you add the new elements? For example, this is an ArrayList, then then I think you would need code similar to If dsFEE_ui.Tables(0).Rows.Count >= FeeformulaTags.Count Then FeeformulaTags.Add(new object()); EndIf so there would be room to add the next tag on the new row. Here is a little try at doing something like this using a hashtable and a primary keycol to do the lookups. http://www.syncfusion.com/Support/user/uploads/GDBG_Formulas_4cbf60dc.zip

Administrator [Syncfusion]
Replied On May 4, 2005 11:18 AM

Thanks for your example Clay as it helped getting my app working Using .Model.RowCount rather than the dataset count solved the problem

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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.

;