Hi,
I have an UltraWinGrid (Infragistics 2007) in which I want to add rows. This UltraWinGrid.UpdateMode is OnCellChange and my datasource is a Linq-to-sql object. On keydown insert, I use the AddRow() method, which creates a new row (yay!) that is invalid for the moment since I have some restrictions on my bound source (no nulls, etc.). The user can then edit the row to make it valid. As long as the user doesn't select another row, or doesn't add a new row (and edits it), my first new row doesn't seem to be submitted to my datasource. However, after selecting another row, or after editing a cell in another new row, my row appears in my ChangeSet.
My questions is "What happened when I selected the other row?". I want to know this because if I have no other rows, I can't find a way to "tell" my new row "Hey buddy, you're good to go!" (with a ctrl-enter or whatever)
Thanks,
Xavier
Hey Tom,
Even though I don't like the concept of toggling a new row, since I was out of idea, I tried it. On save, I go with :
ugIssuerManual.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.ExitEditMode);
ugIssuerManual.DisplayLayout.Bands[0].AddNew();
ugIssuerManual.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.UndoRow);
dal.Update();
Hi Tom,
I must still do something wrong because it doesn't seem to work still. I'll type some actual code of mine, I probably did something wrong :
On KeyDown Insert:
Which triggers the following method ugIssuerManual_AfterRowInsert:
e.Row.Cells["Client"].Value = "";
e.Row.Cells["LastModificationUser"].Value = Environment.UserName;
e.Row.Cells["LastModificationDateTime"].Value = DateTime.Now;
ugIssuerManual.UpdateData();
Hi Xavier,
The behavior you described is your typical "IBindingList" behavior.
The WinGrid band object's AddNew( ) method actually calls the AddNew( ) of the underlying data source. This creates an instance of your object and adds it to your list. During this time, the object is set as the current object that is being edited (by the underlying data source). During this time, values can be added to the properties of your object (through the WinGrid cells). Moving focus off the current record onto another record (which also happens if you call AddNew once again) forces the currently active object to exit edit mode and be committed to the underlying data source. If there are any constraint violations, then you will get that exception (no nulls allowed, etc).
So, how do we address this?
There are several ways. Here are some things to keep in mind: