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
How to add row to grid and populate new row based on another form?
posted

My main windows form contains a grid.  The RowEditTemplate opens when the user clicks on a row in the grid to allow for edits.  I have a "Create folder" button on the RowEditTemplate, whose code-behind will instantiate and open a second Windows form (only contains textboxes).  I'm prepopulating the values in the second Windows form based on the values in the RowEditTemplate.  The fields on the second Windows form are entered by the user then clicks the "Save" button.  I'd like to take the values entered on the second Windows form and create a new row in the grid on the main windows form so the newly-created row can be displayed.  I am able to save it successfully to the datasource, but cannot get it to display as a new row in the grid. 

The code in my  "Create folder" button is:

private void btnCreatefolder_Click(object sender, EventArgs e)
{

    RMSStatic.curr_location = (string)this.ultraGridRowEditTemplate3.Row.Cells[this.ugcpSITE_ID_CURRENT2.ColumnKey].Value.ToString();
    Additional RMSStatic values being saved here, coming from the RowEditTemplate....

   
RMSStatic.activeGrid = "FILES";
    RMSStatic.keepGrid = this.ultraGridRecordsTempVW;

 

     //This is creating the second form (object) and opens
     RMSTestWithLogin.
AddSubfolder s = new RMSTestWithLogin.AddSubfolder();
     s.rmsd = rMSDataSet;
     s.ShowDialog();
}

The code in my "Save" button is:

 private void btnSave_Click(object sender, EventArgs e)
        {
            //Add new Subfolder row to grid
            UltraGridRow aUGRow =  RMSStatic.keepGrid.DisplayLayout.Bands[0].AddNew();
            aUGRow.Cells["FOLDER_TYPE"].Value = "SUB";
            aUGRow.Cells["RECORD_STATUS"].Value = "TEST";
            aUGRow.Cells["SITE_ID_CURRENT"].Value = comboCurrLocLkup.Value;
            aUGRow.Cells["SITE_ID_HOME"].Value = comboHomeLocLkup.Value;
            aUGRow.Cells["DESCRIPTION"].Value = RMSStatic.desc;
            aUGRow.Cells["Action"].Value = "Delete";
            aUGRow.Cells["BAR_CODE"].Value = RMSStatic.barcode;

            string record_Type = "";
            if (comboRecordType.Value != null)
                record_Type = comboRecordType.Value.ToString();

            aUGRow.Cells["RECORD_TYPE"].Value = record_Type;

            RMSTestWithLogin.RMSDataSetTableAdapters.RECORDS_TEMPVWTableAdapter rt = new
            RMSTestWithLogin.RMSDataSetTableAdapters.RECORDS_TEMPVWTableAdapter();

            rt.Connection =
RMSStatic.userODBCConnection;
            rt.InsertSubfolder(record_Type, comboCurrLocLkup.Value.ToString(), comboHomeLocLkup.Value.ToString(), txtMatter.Text, txtDescription.Text,
RMSStatic.volume, RMSStatic.barcode, RMSStatic.inbox);

            rmsd.RECORDS_TEMPVW.AcceptChanges();
            this.Close(); 
       } 

The problem is...the user is able to open the second Windows form and enter the fields OK, but when they click "Save", the record is inserted into the underlying database table (via the "InsertSubfolder" method above), but the grid on the main Windows form is now showing the newly-added record.  I'm trying to use the code in btnSave_Click to add the new row in the grid, but it's not showing.

Should I be doing this differently?

Thank you,

Chris

 

Parents Reply Children
No Data