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
765
NullReferenceException in Ultragrid_AfterRowUpdate
posted

I'm using a RowEditTemplate with my grid.  When the user clicks the OK button in the RowEditTemplate, the code in my "btnTemplateOk_Click" event evaluates the values selected between two fields in the row.  If a "proper" value is not selected, then the user is prompted with a MessageBox and focus is set on the field that needs to be changed.  The user changes the field (to a "proper" value), clicks OK, the value is saved and the template closes.  This is working correctly.  In a second scenario, if the user selects the same row, the template opens, they pick a new value, the template displays the new value, the user clicks OK, the "ultragrid_AfterRowUpdate" event is fired.  This code executes my Update query (I created in the Table Adapter), calls "AcceptChanges()", then returns to the calling method ("btnTemplateOk_Click") which calls the "ultragrid_AfterRowUpdate" event again!  It's during this second call of the "ultragrid_AfterRowUpdate" event that I'm receiving the NullException error (specifically when it hits the code highlighted in red).  I believe its being called a 2nd time due to the "ultraGridRowEditTemplate1.Close(true);" statement where (true) is trying to commit the changes to the data source again?  It seems the references to the UltraGridCellProxy fields are the problem since the template already closed and they do not exist?  Below, I'm showing the code in both my "btnTemplateOk_Click" and "ultragrid_AfterRowUpdate" events.  How can I prevent a second attempt to Update my row again in this scenario???  OR, is there a better way to handle this update?

*********************
*********************
private void btnTemplateOk_Click(object sender, EventArgs e)
{
     //Evaluate value of "Current Location" = Checked Out To and "Checked Out To" IS BLANK
     string currloc_display = (string)this.ultraGridRowEditTemplate1.Row.Cells[this.ugcpSITE_ID_CURRENT1.ColumnKey].Text;
     string checkoutto_display = (string)this.ultraGridRowEditTemplate1.Row.Cells[this.ugcpCO_NET_ID.ColumnKey].Text;
     string checkoutto_value = (string)this.ultraGridRowEditTemplate1.Row.Cells[this.ugcpCO_NET_ID.ColumnKey].Value.ToString(); 

     if
(currloc_display == "Checked Out" && checkoutto_display == "")
     {
            MessageBox.Show("You must select a person in Checked out to:");
            ugcpCO_NET_ID.Focus();
            return;
      }

      ultraGridRowEditTemplate1.Close(
true);
      ultraGrid1.PerformAction(Infragistics.Win.UltraWinGrid.
UltraGridAction.NextRow);
}
**********************************
**********************************
private void ultraGrid1_AfterRowUpdate(object sender, Infragistics.Win.UltraWinGrid.RowEventArgs e)
{
   
//*** BOX
   
if (e.Row.Band.Key == "BOX")
    {
         
this.bOXTableAdapter.Connection = RMSStatic.userODBCConnection;
         
//BOX is being added
          if (BOX_rowinsert == true)
           {
              
this.bOXTableAdapter.InsertBox(ugcpBOX_TYPE.Text, ugcpRECORD_STATUS.Text, ugcpSITE_ID_CURRENT.Text,
                           ugcpSITE_ID_HOME.Text, ugcpJD_BOX_ID.Text, ugcpDESCRIPTION1.Text, ugcpVENDOR_BOX_ID.Text,
                           ugcpCHECKED_OUT_TO2.Text);

               this.rMSDataSet.BOX.AcceptChanges();
               BOX_rowinsert =
false;
            }
          else
           {
                  //BOX is being updated
                  string barcode = (string)this.ultraGridRowEditTemplate2.Row.Cells[this.ugcpBAR_CODE1.ColumnKey].Text;
                  string currloc_value = (string)this.ultraGridRowEditTemplate2.Row.Cells[this.ugcpSITE_ID_CURRENT.ColumnKey].Value.ToString();
                  string currloc_display = (string)this.ultraGridRowEditTemplate2.Row.Cells[this.ugcpSITE_ID_CURRENT.ColumnKey].Text;
                  string homeloc_display = (string)this.ultraGridRowEditTemplate2.Row.Cells[this.ugcpSITE_ID_HOME.ColumnKey].Text;
                  string homeloc_value = (string)this.ultraGridRowEditTemplate2.Row.Cells[this.ugcpSITE_ID_HOME.ColumnKey].Value.ToString();

                 
//If user picked Curr Loc != "Checked Out" and left "Checked Out To" field filled out, then clear out "Checked Out To" field
                  if (currloc_display != "Checked Out" && ugcpCHECKED_OUT_TO2.Text != "")
                   {
                       this.bOXTableAdapter.UpdateBox(ugcpJD_BOX_ID.Text, ugcpDESCRIPTION1.Text, currloc_value, homeloc_value,
                                                                        ugcpOFFICE_CODE1.Text,
null, ugcpBAR_CODE1.Text);

                       e.Row.Cells["CHECKED_OUT_TO"].Value = "";
                   }
                 else
                           this.bOXTableAdapter.UpdateBox(ugcpJD_BOX_ID.Text, ugcpDESCRIPTION1.Text, currloc_value, homeloc_value, 
                                          ugcpOFFICE_CODE1.Text,
                                          (
string)this.ultraGridRowEditTemplate2.Row.Cells[this.ugcpCHECKED_OUT_TO2.ColumnKey].Value.ToString(),
                                           ugcpBAR_CODE1.Text);

                           this.rMSDataSet.BOX.AcceptChanges();
                           e.Row.Cells["Action"].Value = "Delete";
         }
      else
      {
           //*** FILE
           if (e.Row.Band.Key == "BOX_RECORDS_TEMPVW")
           {
                this.rECORDS_TEMPVWTableAdapter.Connection = RMSStatic.userODBCConnection;
                //FILE is being added
                if (FILE_rowinsert == true)
                {
                     this.rECORDS_TEMPVWTableAdapter.InsertRecord(ugcpFOLDER_TYPE.Text, ugcpRECORD_TYPE.Text, "VERIFIED",
                     ugcpSITE_ID_CURRENT.Text, ugcpSITE_ID_HOME.Text, ugcpMATTER.Text, ugcpDESCRIPTION.Text, ugcpWORKING_LYR.Text,
                      ugcpIN_BOX.Text, ugcpCO_NET_ID.Text);

                    this.rMSDataSet.RECORDS_TEMPVW.AcceptChanges();
                    FILE_rowinsert =
false;
                )
              else
               {
                  //FILE is being updated
             string barcode = (string)this.ultraGridRowEditTemplate1.Row.Cells[this.ugcpBAR_CODE.ColumnKey].Text;
                 string currloc_value = (string)this.ultraGridRowEditTemplate1.Row.Cells[this.ugcpSITE_ID_CURRENT1.ColumnKey].Value.ToString();
                 string currloc_display = (string)this.ultraGridRowEditTemplate1.Row.Cells[this.ugcpSITE_ID_CURRENT1.ColumnKey].Text;
                 string homeloc_display = (string)this.ultraGridRowEditTemplate1.Row.Cells[this.ugcpSITE_ID_HOME1.ColumnKey].Text;            
                 string homeloc_value = (string)this.ultraGridRowEditTemplate1.Row.Cells[this.ugcpSITE_ID_HOME1.ColumnKey].Value.ToString();

                 //If user picked Curr Loc != "Checked Out" and left "Checked Out To" field filled out, then clear out "Checked Out To" field
                  if (currloc_display != "Checked Out" && ugcpCO_NET_ID.Text != "")
                   {
                       this.rECORDS_TEMPVWTableAdapter.UpdateRecords(ugcpDESCRIPTION.Text, ugcpMATTER.Text, ugcpOFFICE_CODE.Text,
                                ugcpFOLDER_TYPE.Text, ugcpRECORD_TYPE.Text,
"VERIFIED", currloc_value, homeloc_value,
                                ugcpWORKING_LYR.Text, ugcpIN_BOX.Text,
null, ugcpBAR_CODE.Text);
                       e.Row.Cells[
"CHECKED_OUT_TO"].Value = "";
                   }
                 else
                  {
                       this.rECORDS_TEMPVWTableAdapter.UpdateRecords(ugcpDESCRIPTION.Text, ugcpMATTER.Text, ugcpOFFICE_CODE.Text,
                                ugcpFOLDER_TYPE.Text, ugcpRECORD_TYPE.Text,
"VERIFIED", currloc_value, homeloc_value,
                                ugcpWORKING_LYR.Text, ugcpIN_BOX.Text, ugcpCO_NET_ID.Text, ugcpBAR_CODE.Text);
                   }

                  this
.rMSDataSet.RECORDS_TEMPVW.AcceptChanges();
                  e.Row.Cells["Action"].Value = "Delete";
             }
         }
    }
  }
}

Parents Reply Children
No Data