My main question is this... is there a way to "Cancel" or "Suspend" the grid so when I update a column the "AfterCellUpdate" method will not be called?
I have a windows ultragrid (using 2007 V1), and I have logic in the "AfterCellUpdate" method that is causing me headaches!
Inside the method, I call another method that is outside this UI project. When a user changes the value of the "Destination", "Origination" or "Loading Time" column, I have to call a method to calculate an "Arrival Time".
Example The Loading Time column in a row is set to 4:00 PM the Origination column is New York and the Destination column is Atlanta.
The user changes the Loading Time to 3:00, and the Origination column to Minneapolis. I need to call my outside method to recalculate the Arrival Time... what is happening is that I create a loop in my "AfterCellUpdate" method because I update the Loading Time column (because the date part of that column could change because of the other updates).
Thanks in advance!
Below is my method... I will BOLD the part that loops.
string sourceProductionTypeID = string.Empty; string destinationProductionTypeID = string.Empty;
if (activeCell != null) { try { switch (activeCell.Column.Key) { case "Origination": //update the TransportationGrid with data from the source SITE dropdown
activeCell.Row.Cells["SourceContactID"].Value = _dropDownGridRow.Cells["SiteContactID"].Value;
//call method to update the arrival time marketLoadRecord = SetArrivalTime(); if (marketLoadRecord != null) { //right here is where it loops. As soon as I set the ["LoadingTime"].Value , it fallse right back into the top of this method TransportationGrid.Grid.ActiveRow.Cells["LoadingTime"].Value = marketLoadRecord.LoadingTime; TransportationGrid.Grid.ActiveRow.Cells["ArrivalTime"].Value = marketLoadRecord.ArrivalTime; TransportationGrid.Grid.ActiveRow.Cells["ArrivalDate"].Value = marketLoadRecord.ArrivalDate; }
break;
} } catch (Exception ex) { MessageBox.Show(ex.Message, "TransportationGrid_AfterCellUpdate Error", MessageBoxButtons.OK); } }}
You can use the EventManager to disable the event while you are in it.
Something like this:
grid.EventManager.SetEventEnabled(GridEventIds.AfterCellUpdate, false)
try
{
// Your code here
}
finally
grid.EventManager.SetEventEnabled(GridEventIds.AfterCellUpdate, true)
Use the beforeCellUpdate method to set the SourceContactID, loading time, ArrivalTime, ArrivalDate