I have a ultrawingrid on a form bound to a collection of business objects. The business object has a child collection that is also displayed in the grid as a child band. I am updating the child collection in the beforerowexpanded event. When new items are added to the object however, the grid does not display them. I have stepped through the code in the debugger and the e.Row.ListObject given shows the correct elements, the grid just doesn't display them.
Has anyone else seen this issue and have a possible workaround? I have even tried calling the DataBind method on the grid and it still does not display the new data. Note that when I remove all items from the collection, the grid does reflect the changes, but if I add or remove items (leaving at least one) it does not.
I have exactly the same problem...
My grid is bounded to a BindingSource filled with a list of entities... those entities have sub-lists that are displayed in child bands..
I have implemented drag&drop to be able to drop objects over the list so they are added to the list... Here is the OnDragDrop :
Protected Overrides Sub OnDragDrop(ByVal drgevent As System.Windows.Forms.DragEventArgs) MyBase.OnDragDrop(drgevent) If Me.ObjetoDragValido(drgevent) Then Dim oRowsDestino As IList = Me.ObtenerRowsDestino(drgevent) If (oRowsDestino IsNot Nothing AndAlso oRowsDestino.Count > 0) Then Dim oRows As SelectedRowsCollection = TryCast(drgevent.Data.GetData(GetType(SelectedRowsCollection)), SelectedRowsCollection) Dim oList As New List(Of Object) If oRows IsNot Nothing Then For Each o In oRows oList.Add(o.ListObject) Next End If For Each oDestino As UltraGridRow In oRowsDestino If (TypeOf oDestino Is UltraGridRow _ AndAlso TypeOf oDestino.ListObject Is IDragDrop) Then
CType(oDestino.ListObject, IDragDrop).DoDrop(oList) Dim o As Object = oDestino.ListObject oDestino.Activate() oDestino.Expanded = True End If Next End If End If End Sub.
The DoDrop call does add some objects (the dropped ones) to the list included in the entity of the row (ListObject).
After lots of testing I've found the following:
If I drop objects on a collapsed row.. they get added and on expand they show...If once the row is expanded I drop some more, they don't appear (even when the entity's list in watch window shows the new ones)If the row is expanded but there are no child rows... it works, I drop some and they show....
Well, the behavior is really weird... I don't find a method to "reload" the child rows from one given row... is that possible? What am I doing wrong?
I've already tried to refresh the grid, using .DataBind(), using row.Update(), row.Refresh() ... they all have the same behavior...
I need help for this, please!!
An IList is not a very robust interface and it will not notify the grid (or any other control) that rows have been added. You might want to consider using BindingList<T> a DataTable, or an UltraDataSource, all of which implement IBindingList which is a much more powerful interface for binding.
If that's not a possibility, you can try calling grid.Rows.Refresh(ReloadData). I thin this method has a parameter for recursive, so you will want to pass in true for that. Or, you could probably call the same method on the actual rows collection where the new row(s) was added.
If that still doesn't work, then the only other thing I can think of is to set the grid's DataSource to null and back.
jvilarino said:I can try to change to BindingList(Of T), but I don't think it really makes a differnence... you think it will with the setup I've just pasted here?
Yes, absolutely. List<T> does not send notifications to controls when new items are added. If they are showing up sometimes, then the grid is probably getting refreshed for some other reason and it's a fluke. BindingList<T> is a much more robust interface designed specifically for data binding. It sends a lot more notifications to bound controls.
I didn't express myself quite well...
I used your grid's wizard to point to one of the classes of my application, and it automatically creates an UltraDataSource and a BindingSource for the grid... Later, programmatically I do this to bind the list:
Dim oList As New List(Of clsDerecho)
ClsDerechoBindingSource.DataSource = oList
Anyway, the behavior is very erratic when adding objects to the child band's list... sometimes they appear and sometimes they won't. But if I check the list of entities, the new objects are added...
I can try to change to BindingList(Of T), but I don't think it really makes a differnence... you think it will with the setup I've just pasted here?
Thanks
[EDIT]
I've changed the internal lists of the Entity to BindingList and the source list for the Bindingsource object to a LinQ query and it seems to work pretty well.... I'll do some more testing and report here if it worked.
Example:
ClsDerechoBindingSource.DataSource = From oObj As clsDerecho In Me._businessObj.GetList()
Seems to work better