Hi,
maybe this is an easy task but I couldn't solve it. til now
I've an object that is bound to a WinGrid using a BindingSource. This object has some properties like strings etc. and a property with a list (System.Collections.Generic.List<T>) containing objects of another class. This list is shown in the VS Designer as an extra band.
Since I'm only interested in showing some of the properties of the 'main' band and not the additional band I set this to hidden which works pretty fine but the property still gets accessed although it's data is not presented. The problem is that this property uses lazy initialization, fetching the data from the database which is unnecessary because it's not getting displayed at all.
My question is can I disable an entire band or is there another possibility to overcome accessing the property?
Thanks in advance, Wolfgang
Hi Wolfgang,
qbupoew said:but the property still gets accessed
Can you post the call stack when the property is being accessed? The grid should not be trying to access the value of a field which represents a hidden band. That might be a bug.
In addition to what Vince suggested above, you might want to try setting the grid.DisplayLayout.ViewStyle to SingleBand and see if that helps.
Also, try setting MaxBandDepth to 1.
But even if those work, you should not have to set them.
Hi Vince and Mike,
thanks for your instant replies. I didn't try Vince's suggestion with the WinDataSource but set the ViewStyle to SingleBand since that was easier to do but the property for the second band still gets accessed!
Here ist the call stack:
Invoicing.dll!Altova.Invoicing.Invoice.Orders.get() Line 318[External Code]OrderManagement.dll!Altova.OrderManagement.DoneOrders.DoneOrders.OnOrderSelected(object sender = {Infragistics.Win.UltraWinGrid.UltraGrid}, System.EventArgs e = {System.EventArgs}) Line 554 + 0x13 bytes[External Code]OrderManagement.dll!Altova.OrderManagement.Common.OrderUserControl.SelectFirstRowInGridView(Infragistics.Win.UltraWinGrid.UltraGrid gridView = {Infragistics.Win.UltraWinGrid.UltraGrid}) Line 1222 + 0x10 bytesOrderManagement.dll!Altova.OrderManagement.DoneOrders.DoneOrders.OnFormLoad(object sender = {Altova.OrderManagement.DoneOrders.DoneOrders}, System.EventArgs e = {System.EventArgs}) Line 298 + 0xe bytes[External Code]OrderManagement.dll!Altova.OrderManagement.ModuleController.ShowView(object view = {Altova.OrderManagement.DoneOrders.DoneOrders}) Line 185 + 0x3a bytesOrderManagement.dll!Altova.OrderManagement.ModuleController.HandleDoneOrdersEvent(object sender = {Altova.OrderManagement.OrderManagementControl}, System.EventArgs e = {System.EventArgs}) Line 420 + 0xe bytes[External Code]OrderManagement.dll!Altova.OrderManagement.OrderManagementControl.OrderManagementControlTreeView_OnAfterSelect(object sender = {Infragistics.Win.UltraWinTree.UltraTree}, Infragistics.Win.UltraWinTree.SelectEventArgs e = {Infragistics.Win.UltraWinTree.SelectEventArgs}) Line 235 + 0x15 bytes[External Code]Infragistics.Practices.CompositeUI.WinForms.dll!Infragistics.Practices.CompositeUI.WinForms.IGFormShellApplication<Microsoft.Practices.CompositeUI.WorkItem,Altova.Acs.ShellForm>.Start() Line 25[External Code]Acs.exe!Altova.Acs.ShellApplication.Main() Line 40 + 0x1e bytes[External Code]
In line 554 the DataSource is bound to a new list of objects. Important to say is that the UltraGrid sending the event is not the UltraGrid where I'm newly setting the binding!
Here is the code snippet:
// Get the invoice from the database var invoices = Invoice.Get(new InvoiceCriteria {InvoiceId = _selectedOrder.InvoiceId}); // This is line 554invoiceBindingSource.DataSource = invoices;
var invoices = Invoice.Get(new InvoiceCriteria {InvoiceId = _selectedOrder.InvoiceId});
// This is line 554invoiceBindingSource.DataSource = invoices;
invoiceBindingSource is the BindingSource object used for data binding.
In line 318 of Invoice the property is being accessed. Here is the code snippet:
public List<Order> Orders{ get { if (_orders.Count == 0) _orders = Order.Get(new OrderCriteria() {InvoiceId = this.InvoiceId}); return _orders; } }
}
As you can see here is that we are using lazy initialization here to get the orders from the database. Orders are a second band that should not be displayed at all as I mentioned in my initial posting.
I don't know if this was helpful to you because you cannot see much in the call stack. If there is anything I can provide to you don't hesitate to contact me again.
Kind regards, Wolfgang
I don't see any code in your call stack that references the WinGrid. Maybe that's the "[External Code]". I think maybe there is a way in Visual Studio to turn on the display of the external code so you can see what's happening. there. Maybe on the context menu in the Call Stack Window?
qbupoew said:Important to say is that the UltraGrid sending the event is not the UltraGrid where I'm newly setting the binding!
I'm a little confused by this. You have more than one grid bound to the same data source?
Hi Mike,
sorry about the confusion concerning the two grids. They are not bound to the same data source and all that I wanted to say is that the event is fired from another grid. Anyhow, it has nothing to do with the real problem.
I've prepared a very simple project that demonstrates it.
It consists of a simple class 'User' that has the properties 'FirstName' and 'LastName' that are of type 'string'. It has also a property 'Roles' that is of type 'List<string>'. I've created a binding source out of class 'User', bound it to a WinGrid and got 2 bands, one for the 'User' object and another for the 'Roles'. I set the ViewStyle in DisplayLayout to SingleBand so the 'Roles' are not displayed yet if I set a breakpoint on the 'Roles' getter it is being called. This is exactly the same behaviour I'm experiencing in my 'real' application.
Although I hope you can easily work with that sample here is the callstack with more details from the breakpoint:
I hope that uploading of the ZIP-File worked. If you need any further assistance don't hesitate to contact me again.
qbupoew said:Although I can understand that you don't want to change the actual behaviour since it could break existing applications but on the other hand it makes things not very obvious and maybe there will be other customers complaining on that but it is your decision if you treat that as a bug or not.
I agree with you. The problem is that some application out there could be referencing the child band in code even though it's not displayed in the grid. If we changed this, that application would suddenly start blowing up because the child band won't be there any more.
It would be great if we could change it and you are right that it would alleviate some confusion. But I just don't think it's worth the risk in this case.
I approved your good news by setting MaxBandDepth and it works both in the Test Application I've sent you in my last posting and in my real application - thanks for that.
Although I can understand that you don't want to change the actual behaviour since it could break existing applications but on the other hand it makes things not very obvious and maybe there will be other customers complaining on that but it is your decision if you treat that as a bug or not.
Hi WolfGang,
It appears that the grid doesn't look at the Hidden property on the band, nor the ViewStyle property when determining whether or not to get the child bands. This might be a bug, but it's probably not something we want to change at this point, since it could break existing applications.
The good news is that the grid does look at the MaxBandDepth. So if you set MaxBandDepth to 1, it will solve the problem in this test application.