Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3555
Cell Calculations Group By
posted
I attached screenshots of my application...

I have posted this problem before, but the solution proposed doesn't seem
efficient. And I just think there has to be a better way. The solution
proposed is to loop through the enumerator collections. Do I really have to
loop through it, is there no way to reference a particular cell in that
collection without writing code to loop through it?

So this procedure works for non grouped, as you can see it changes values of
the dependent cells. Can anyone send me a small example of how I can handle
this no matter what columns I group by (I won't be grouping the date
columns, 2006, 2011, 2016).

The problem I see is that the grouping changes the order of the rows, thus
the current procedure will not work as the dependent calculated cells are no
longer one after the other so CurrentRow + 2 will reference the wrong cell,
so I guess I have to change it so that I get a unique combination reference
like (Pop, Country, Epi and the current date column )

private void CalculateGridCells()

{

//Get Current Row

int CurrentRow = ultraGrid1.ActiveCell.Row.Index;

int CurrentCol = ultraGrid1.ActiveCell.Column.Index;


//Enable Cells Editing

DeactivateRows(false);


//Disable AfterCellUpdate Event

this.ultraGrid1.EventManager.SetEnabled(GridEventIds.AfterCellUpdate,
false);

try

{


switch (this.ultraGrid1.Rows[CurrentRow].Cells["Epi"].Value.ToString())

{

case "Input Prevalent Population":


ultraGrid1.Rows[CurrentRow + 2].Cells[CurrentCol].Value =
(int)ultraGrid1.Rows[CurrentRow].Cells[CurrentCol].Value *
(int)ultraGrid1.Rows[CurrentRow + 1].Cells[CurrentCol].Value;

ultraGrid1.Rows[CurrentRow + 4].Cells[CurrentCol].Value =
(int)ultraGrid1.Rows[CurrentRow + 2].Cells[CurrentCol].Value *
(int)ultraGrid1.Rows[CurrentRow + 3].Cells[CurrentCol].Value;

break;

case "DR Percentage Diagnosed":

ultraGrid1.Rows[CurrentRow + 1].Cells[CurrentCol].Value =
(int)ultraGrid1.Rows[CurrentRow].Cells[CurrentCol].Value *
(int)ultraGrid1.Rows[CurrentRow - 1].Cells[CurrentCol].Value;

ultraGrid1.Rows[CurrentRow + 3].Cells[CurrentCol].Value =
(int)ultraGrid1.Rows[CurrentRow + 1].Cells[CurrentCol].Value *
(int)ultraGrid1.Rows[CurrentRow + 2].Cells[CurrentCol].Value;

break;

//case "Diagnosed Population": Not needed calculated field

case "DR Percentage Treated":

ultraGrid1.Rows[CurrentRow + 1].Cells[CurrentCol].Value =
(int)ultraGrid1.Rows[CurrentRow].Cells[CurrentCol].Value *
(int)ultraGrid1.Rows[CurrentRow - 1].Cells[CurrentCol].Value;

break;

//case "Drug-Treated Population": Not needed calculated field

default:

//dostuff;

break;

}

}

finally

{

this.ultraGrid1.EventManager.SetEnabled(GridEventIds.AfterCellUpdate, true);

DeactivateRows(true); //Lock Rows

}




}
Parents
No Data
Reply
  • 45049
    posted

    You'll probably be better off doing these calculations in your data source, rather than in the grid.  That way, the calculations will remain consistent regardless of how you sort or group the grid.

    If you were modifying values in the current row, rather than in subsequent rows, you might be able to leverage the ListIndex property of the UltraGridRow object.  This represents the index of the data item which the row represents, which remains unchanged when the grid is sorted or grouped.  There's a "GetRowAtListIndex()" method on the RowsCollection object, but this becomes excessively difficult to implement in conjunction with grouping (since this moves rows to new rows collections).

    Please remember that these forums area a peer-to-peer resource to share issues and ideas with other Infragistics users.  If you require official support from Infragistics, please submit a support request to Infragistics Developer Support from this page of our website.

Children
No Data