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
AD
Administrator
Syncfusion Team
May 3, 2005 10:28 PM UTC
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?
AD
Administrator
Syncfusion Team
May 4, 2005 08:22 AM UTC
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?
AD
Administrator
Syncfusion Team
May 4, 2005 11:35 AM UTC
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.
AD
Administrator
Syncfusion Team
May 4, 2005 01:08 PM UTC
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....
AD
Administrator
Syncfusion Team
May 4, 2005 02:23 PM UTC
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
AD
Administrator
Syncfusion Team
May 4, 2005 03:18 PM UTC
Thanks for your example Clay as it helped getting my app working
Using .Model.RowCount rather than the dataset count solved the problem