I have a WinGrid that is bound to a BindingSource and it hooks up tio Oracle database. It has 8 bands (aka 7 child tables hooked together w/ relations).
I have a request to duplicate the current record (aka duplicate all bands beneath the current record) and thus change the keys to make a unique primary key.
I can manually add to the table adapter which adds to the database but when I call Grid.Update(), it doesn't show the newly created record. I figured the best way was to add to the grid and then get the DataRow from there and push into the database. The problem is I do not see the easy calls to do this.
UltraGridRow newFMECARow = FMECAGrid.DisplayLayout.Bands[2].AddNew();
This causes the row editor (aka template editor to fire). I want to pass it the new row (aka, let me fill it in and remove the user interaction (I want to pass a new UltraGrid row to addnew).
I would like to do something like the following:
newFMECARow.Cells["OBJECT_TYPE"].Value = FMECAGrid.ActiveRow.Cells["OBJECT_TYPE"].Value;
newFMECARow.Cells["TECHNOLOGY_TYPE"].Value = FMECAGrid.ActiveRow.Cells["TECHNOLOGY_TYPE"].Value;
newFMECARow.Cells["TITLE"].Value = FMECAGrid.ActiveRow.Cells["TITLE"].Value;
newFMECARow.Cells["DOCUMENT_NO"].Value = "Copy of" + FMECAGrid.ActiveRow.Cells["DOCUMENT_NO"].Value;
newFMECARow.Cells["LAST_MODIFIED_BY"].Value = WindowsIdentity.GetCurrent().Name;
newFMECARow.Cells["LAST_MODIFIED_DATE"].Value = DateTime.Now;
FMECAGrid.ActiveRow = newFMECARow;
Is there a way of doing this easily - looked at samples and it wasn't exactly clear how to do but it must be doable.
Hi,
I'm having a hard time understanding the problem(s) you are having.
You can certainly add new rows directly to the grid. What do you mean by: "This causes the row editor (aka template editor to fire)."
If you are adding a row to the grid in code and the RowEditTemplate is displaying to the user, then something is wrong. That should not be happening.
I'm also not sure what you mean when you say you are adding rows to the TableAdapter. Typically, if you want to add rows to the grid, you would have to either add them to the grid itself or to the grid's DataSource. The DataAdapter deals with the interaction between the data source and back end, it has nothing to do with the grid.
So you might want to consider adding the rows directly to the grid's DataSource - whatever DataSource you are using. As long as your DataSource support IBindingList (and not just IList), the grid will be notified of the changes and display the newly-added rows.
Yes, the RowEditTemplate does display for me when I call the following:
Is that the correct code to add a new row?
I have it working by adding it to the dataset and then updating the grid as you say. I guess I am doing it correct although the dataset is parameterless (aka insert into dataset is just an object[] so you need to know the order of fields).