Hi,
I am trying to update a readonly column when user modifies value in another column. Ingragistics identifies that if the cell value is same then it does not fire the AfterCellUpdate event. Sample code is pasted below.
In the below example after i click button1 , i load the grid's datasource. Then i go to EmpDayHours and modify the value from 5 to 8 and tabout of the cell. This will hit the AfterCellUpdate event and inside switch it will first match nCol = 3 (because we edited EmpDayHours) this will go to SetEmpSalary and setting value will once again trigger the AfterCellUpdate , now this time in the switch it will go to default and call the SetEmpSalary again but this time we are trying to set the same value and the AfterCellUpdate event wont fire. In my actual code since it does not fire the AfterCellUpdate event at this point some other columns dependent on this column do not get updated. Is there a way to let Infragistics know to fire the event again by making the cell's state dirty or any other way.
Thanks - Keerti
public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable("EmpDataTable"); dt.Columns.Add(new DataColumn("EmpId" , typeof(string))); dt.Columns.Add(new DataColumn("EmpName" , typeof(string))); dt.Columns.Add(new DataColumn("EmpSalary" , typeof(float))); dt.Columns.Add(new DataColumn("EmpDayHours" , typeof(float))); //add a row DataRow dr = dt.NewRow(); dr["EmpId"] = "61614"; dr["EmpName"] = "Keerti"; dr["EmpSalary"] = 50000; dr["EmpDayHours"] = 5; dt.Rows.Add(dr); ultraGrid1.DataSource = dt; } private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { } private void ultraGrid1_AfterCellUpdate(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { int nCol = e.Cell.Column.Index; int nRow = e.Cell.Row.Index; switch (nCol) { case 3: SetEmpSalary(nRow , 89000); SetEmpSalary(nRow , 89000); break; default: SetEmpSalary(nRow, 89000); break; } } private void SetEmpSalary(int nRow , float salary) { ultraGrid1.Rows[nRow].Cells["EmpSalary"].Value = salary; }
I don't understand what you are trying to do here. The event fires for the EmpSalary column once when the value changes. Why would you want the event to fire a second time when the value is not changing. That doesn't make any sense.
If, in your real application, you want the change to the EmpSalary column to trigger an AfterCellUpdate which will then change other columns, then this is already happening and you don't need the event to fire a second time.
In fact, if the event did fire, your code would get stuck in an infinite loop and eventually blow up with a StackOverflow Exception.
BTW... it's not a good idea to use the column index here. If the columns are rearranged, then your code will no longer work. You should really use the column key.
Mike , Thanks for your quick reply. there was a code change from our side which led to an issue and made me think otherwise.
Sorry for the post. Thanks
Hello,
Is there anything further that we can do to help?
Hello Sir
Please Help me
This is correct behavior. Why would you want the event to fire when nothing has changed?
Hiiii Sir
Because I Want Re-Edit Cell Value (Same Value) Then Call AfterCellupdate Events
Please Help Me
I'm not sure how to help you. The event will not fire when there are no changes in the cell. There is no reason why it should and there's no reason to make it fire, other than perhaps setting the value to something else and then back again. Maybe you should be using a different event like AfterCellDeactivate or AfterExitEditMode.
Well, the event is not going to fire in that case and there is no way to make it do so. The best I can offer you is some suggestions about alternative UI, like perhaps you could put a button on the form or in the cell that resets the default values in the other cells.
I can give you a reason why it should be allowed.
Example: The cell being set back to the same value (call this cell X) causes other cells to get a default value, however those additional cells can be overridden.
In this case, the User should not have to first select a different value in cell X and then re-select the desired value to get the related cells to be reset to their default value. Re-selecting the same value should be sufficient for this, but since this will not trigger the AfterCellUpdate event, it is not.
At the very least, there should be a way to force the before & after events (as well as any others that make sense) to fire to allow handling this situation.