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;
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
Hi Chris,
I guess I am really just not getting what you mean by "subfolder" or "pocket row". If these are not child rows, then what are they? Is this just a field in the row that happens to be a class type and has it's own set of properties? If that's the case, then I guess it might make sense to show the extra dialog to allow editing of that field.
I'm not sure how this would work bound. I don't know if it's possible to bind the fields of a field in a row to a control. You might have to just manually update the child properties of the object in the data source you are using.
I think I understand what you have proposed. My grid only has a single band. I do not have a parent/child relationship (2 bands) setup for this grid. The "pocket" row and "subfolder" rows reside in the same grid. The only difference is the FOLDER_TYPE column. The "pocket" row has a FOLDER_TYPE = "pkt" and the "subfolder" row has a FOLDER_TYPE = "sub". The user clicks the "pocket" row and the RowEditTemplate for this grid opens. This RowEditTemplate has the "Create subfolder" button. Clicking the "Create subfolder" button opens the second form with prepopulated values from the "pocket" row. I didn't think I could re-use the same RowEditTemplate to create the "subfolder" row. The second form has a SAVE button and I was thinking the code behind this SAVE button could create the new "subfolder" row in the same band in the grid. Is this what you're suggesting by adding a child row? (Sorry if that's what you intended, just want to make sure I understand.)
Thanks,
It sounds to me like you need to just set up a RowEditTemplate for the child rows, then just move the current position of the CurrencyManager to a child addnew row. You could just add a child row to the band of the grid and then set the grid's ActiveRow, I think. It's hard to say exactly what you need to do without knowing more about your application. But the RowEditTemplate is tied to the ActiveRow in the grid. So if you are editing a row in the grid and you add a child row to that row through the grid and set that as the ActiveRow, then the RowEditTemplate should appear for that row. I'm not sure if yuo can have both RowEditTemplates up at the same time, if that's what you want, though.
My intent is to provide the user with a method of associating new subfolder(s) with an existing pocket (for Records keeping). My grid shows the pockets. The user can open the pocket (record) in the grid to display the details of the pocket. While the RowEditTemplate is open, they can click a button to create a subfolder associated with that pocket. When I first put this together, I didn't know how else to use the details from the pocket to prepopulate values in the new subfolder (record). That's why I created a separate form. The end goal is to give the user the ability to create new subfolders within an existing pocket. Maybe I need to do this in reverse...let the user first create the new subfolder (record) using the RowEditTemplate and have the a combo list provide the list of available pockets to choose from to make the association?
How would I programmatically add a new row using the RowEditTemplate? I'd like to use the values obtained from the second form to add the new row.