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).
As I understand it you wanted to know how to add a row to the grid in code. Have you accomplished what you wanted to do? Is there anything more we can help you with?
Yes, I got what I needed to do to work. So for all intensive purposes it is resolved. Just looking for information now since really not an issue...
The issue is (in the future - aka got it working so don't need to know now because it is working) how does one add a row programatically in the grid without updating the dataset and updating the gird (aka Grid.Update) => aka update grid and then Grid.UpdateData to push out changes to the dataset.
aka doing things in the opposite order -> the posts seem to indicate this is perfectly ok, however when I tried AddNew it fired off the Row Template Editor - any reason for the editor showing up or the add new is correct and there is something incorrect in the way I am doing something. If doing it in the opposite order is frowned upon, just close this issue since not a big deal -> more of just interested in knowing than any actual problem at this point.
I'm glad it's working and I think you should do this in the order in which you are now doing it.