I have a situation that works fine when using windows databinding, however I am not using WindowsDatabinding.
I have a hierarchail data source that is a BindingList<Part> each object in this list has a sub list, also BindingList<T> that contains Unit of Measure objects.
I do the following code in InitalizeRow even handler:
foreach (IGridBandExpression bandExpression in _properties) { if (e.Row.Band.Key != bandExpression.BandKey) continue; foreach (var property in bandExpression.Properties) { if (property.UseChildBandForValueList) { ValueList valueList = new ValueList(); if (e.Row.ChildBands != null) { foreach (var row in e.Row.ChildBands[property.ChildBandName].Rows) valueList.ValueListItems.Add(row.Cells[property.ValueListColumnKey].Value); e.Row.Cells[property.ColumnName].ValueList = valueList; } } } }
This code basically loops through my list of properties that I have defined for the Grid Control and when it gets to a row that is supposed to use a child band for a value list, it creates it. Nothing fancy, and it works, until i set the childBand.hidden = true in InitializeLayout. It does load the value list object from the child band for objects that are in the list when the control is bound.
Now the parent band contains Part objects. When you pick a new part from the drop down list in the PartNumber column, this triggers an event to load the part information, including the ChildList of UOM objects. The list is populated but the child band never gets the data when it is hidden.
Any ideas?
Thanks for the help Mike, I was looping through the child band rows because the datatype is unkown at design time (I have build a Fluent Binding interface on top of the grid). So that was the easisest way to use whatever type of object the list was.
I ended using a little bit of reflection to make this work (since the list is generic)
Thanks,
Ryan
I'm afraid I am having a hard time understanding your question.
What part of this isn't working. The InitializeRow event is not supposed to fire for invisible rows. That would not make sense, since it would be a huge waste of resources to initialize something the user will never see.
But I'm not sure why that would matter. It looks like your code is creating a ValueList in the parent row by looping through it's child rows. I'm not sure why you would want to do it this way - this doesn't seem very efficient to me. You would be better off just building the ValueList directly from the data source rather than using up memory by have extra bands in the grid that are never displayed. And looping through the cells of those invisible rows is going to eat up even more unneccessary memory.
You might want to take a look at the WinGrid Performance Guide.
But efficient or not, I don't see any reason why the code you have you here should not work. What exactly isn't working?