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
390
AfterCellUpdate
posted

I have a grid in Visual Studio 2008 that uses AfterCellUpdate to call an SQL update command and, while the code runs after grid cell edits, the correct cell values get passed as parameters only if I click off the cell onto another cell in the same row, and not if I click off the edited cell and onto a different row. With the same results, I've tried in the grid InitializeLayout event to set UpdateMode to OnCellChange and OnCellChangeOrLostFocus. I'll include my code below. Probably my errors are obvious to someone.

private void ugridUT_AfterCellUpdate(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
{
                UltraGrid grid = (UltraGrid)sender;
                UIElement lastElementEntered = ugridUT.DisplayLayout.UIElement.LastElementEntered;

                if (lastElementEntered == null)
                    return;

                UltraGridRow row = lastElementEntered.GetContext(typeof(UltraGridRow)) as UltraGridRow;

                    StringBuilder sb = new StringBuilder();
                    sb.Append("UPDATE MYTABLE ");
                    sb.Append("SET FIELD1 = '");
                    sb.Append(row.Cells["FIELD1"].Value.ToString().Trim());
                    sb.Append("', ");
                    sb.Append("FIELD2 = '");
                    sb.Append(row.Cells["FIELD2"].Value.ToString().Trim());
                    sb.Append("' ");
                    sb.Append("WHERE TABLE_PK = '");
                    sb.Append(row.Cells["TABLE_PK"].Value.ToString().Trim());
                    sb.Append("' ");

                OracleConnection myConnection = new OracleConnection(oracleConnection1.ConnectionString.ToString());
                OracleCommand myCommand = new OracleCommand(sb.ToString(), myConnection);
                myCommand.Connection.Open();
                myCommand.ExecuteNonQuery();
                myConnection.Close();
                myCommand.Dispose();
}

 

Parents
No Data
Reply
  • 37774
    Suggested Answer
    posted

    The main issue that I see is that you're using the LastElementEnterered property of the grid's UIElement, which can change based on where the mouse location is and could not have anything to do with the cell that is being updated.  The CellEventArgs provider a Cell property that you can work with instead:

    UltraGridRow row = e.Cell.Row;

    ...

    -Matt

Children
No Data