Hi,
I have a problem when I use ControlContainerEditor in ultragrid. I want to use the templateAddRow to add new row in the grid. So I set the AllowAddNew to be "TemplateOnTop" and I use the same control for Editor and Rendering. When the grid is empty it shows the new template row and I can input data in that new row. But the problem is unlike normal grid it can not automatically save the new row and add another template new row on the top. So that I can't create new row by using templateAddRow method.Does anyone know how to implement this?
Thanks,
My guess is that there's a problem with the control you are using for editing. The grid has to get a notification from the editor that something in the cell has changed. So your control needs to fire an event whenever the property that contains the value changes. So if you are using a property called Value, then your control need to fire a ValueChanged event. Or, if you are using the latest version, I think we also have support for INotifyPropertyChanged.
Actually I already implemented INotifyPropertyChanged interface for the class which is bound to the editor and rendering control. For existing rows the grid can update properly but it can't update when the row is the TemplateAddNew row. I will try to raise ValueChanged event to see if it works and check my codes to see if my codes have bugs. Thanks,
INotifyPropertyChanged support was not implemented in the initial release of the UltraControlContainerEditor. We added it in a recent service release. So, depending on which version of NetAdvantage you have, you might just need to update to the latest Service Release.
How to get the latest service release - Infragistics Community
Having said that, there's no reason why this would work in a regular row and not a TemplateAddRow, so unless you are also editing other cells in the regular row and not doing that in the TemplateAddRow, that's probably not the issue.
Are the RowSelectors visible in the grid? If not, you might want to turn them on, just as a test. As soon as you edit the value in your contained control, the RowSelector for that row in the grid should show a pencil icon to indicate a pending change. This should happen for both existing rows and TemplateAddRows. If that's not happening, then something is wrong. Maybe your editing control is not firing the event on every keystroke or mouse click that causes the value to change?
It might help if I knew what kind of control you are using. Is it a UserControl? If so, what kinds of controls are in it?
If you could post a small sample project demonstrating the issue, I'm sure I could tell you why it's not working.
Hi Mike,Thanks for your quick reply. After I did service release update, the problem was still there. To let us working on the same page, I used the ControlContainerEditor sample solution to do this test. Here are what I did:1) Install service release update for 2010 v22) Open C# sample solution for ControlContainerEditor3) Under Folder "Same Editor and Render Control", open AddressControl.cs and add codes in the begin of the txt_TextChanged method to avoid error: if (this.address == null) this.address = new Address("Street1", "City1", "CA", "12345");4) Open "SameRenderandEditForm" form and change the ultragrid1.displaylayout.bands(0).override.AllowAddNew to be "TemplateOnTop"5) Run the app6) You will see the TempleAddRow can't be inserted and when you click a existing row, the TemplateAddRow will be filled with the content of the selected row.These all I have done and hope it can give you some clues what the problem is.Thanks,
There are two issues here. The first one is one that you sorta ran into but your solution isn't quite right. Your idea of checking for null in the txt_TextChanged event is on the right track, but it's too late.
When you click on the cell in the Template AddRow, the UltraControlContainerEditor tries to apply the value of the field in the grid to the AddressControl.Address property. This is failing, because the value in the field is DBNull.Value and the Address property is of type Address, so it cannot accept DBNull.
So rather than checking for null in TextChanged, one thing you could do is initialize the default value of the grid cell to something that the Address control can handle:
private void ultraGrid1_InitializeTemplateAddRow(object sender, Infragistics.Win.UltraWinGrid.InitializeTemplateAddRowEventArgs e) { e.TemplateAddRow.Cells["Address"].Value = new Address("Street1", "City1", "CA", "12345"); }
It would probably be a good idea for it to try using null instead of DBNull in a case like this. We already do that if you use a Nullable type, but apparently not when you use a reference type, even though it can accept null.
The second issue is that the AddressControl is not sending any notification when the Address is changed. This class does not implement INotifyPropertyChanged and it does not fire an AddressChanged event. So the grid has no way of knowing that the field is dirty and doesn't create a new TemplateAddRow.
This is sort've odd, because if this field was anything other than a reference type, the sample would not work when you edit a regular row. The grid actually has no idea that the data is dirty when you edit this field. The thing is - it doesn't need to know in the case of an existing row, because the value of the cell does not actually change. It's only properties on the object in the field that change. So that's probably why no one noticed it until now.
The Address class implements INotifyPropertyChanged, but the AddressControl does not. The AddressControl is already hooking the PropertyChanged event on the Address to update it's UI. So to fix this, you have to implement INotifyPropertyChanged on the AddressControl and fire PropertyChanged from the address_PropertyChanged method, and also any time the Address property is set.
GREAT. It worked after I did code changes as you suggested. Thank you so much for your detailed explanation on this issue.
Thanks again