Hi,
I have encountered the following issue: I have a grid with two bands in it. It is bound to a UltraDataSource with two bands: the root band is called UnitateBand and the child band is called GestiuneBand. When I first populate the grid, it is drawn ok, with the correct number of children rows for each root row.
When I am repopulating the grid I'm trying to reset the count of the each children row collection for each root row to the new value. It works fine for the children rows of the root bands except for the first row. In its case the number of children rows is not changing, so if a new child is available a child row is hidden, depending on the sorting. When a child row is deleted an empty row is shown in the grid. For the root rows with index greater than 0, the issue is not manifesting.
The code I'm using to populate and repopulate the grid is:
{
Func func = delegate
// set the number of root rows which will contain unitati
_unitatiGestiuniDataSource.Rows.SetCount(listaUnitati.Count);
int contorUnitati = 0;
UltraDataRow dataRow = _unitatiGestiuniDataSource.Rows[contorUnitati];
dataRow["Cod"] = unitate.Cod;
// find the available gestiuni for the curent unitate
// and add them to the child band
delegate(BOGestiune gestiune) { return gestiune.CodUnitate == unitate.Id; });
childRows.SetCount(gestiuniTemp.Count);
int contorGestiuni = 0;
UltraDataRow childDataRow = childRows[contorGestiuni];
childDataRow["Cod"] = gestiune.Cod;
childDataRow["Tip"] = gestiune.TipGestiune.Denumire;
childDataRow["SeFactureaza"] = gestiune.SeFactureaza;
childDataRow["SeVindeCasaDeMarcat"] = gestiune.SeVindePrinCasaDeMarcat;
contorGestiuni++;
}
contorUnitati++;
// make sure all unitati and gestiuni are visible
};
Invoke(func);
The comments have been translated to english, and I've tried to keep the romanian meaning.
Am I doing something wrong, or is this a bug?
Hi Mike,
Mike Saltzman"]I think your best bet would be to create a small sample project that demonstrates the problem and Submit an incident to Infragistics Developer Support.
I have made and submited to the Developer Support a sample project.
Mike Saltzman"]Also, you might want to try calling grid.Rows.Refresh(ReloadData) and see if that helps, just as a workaround for now. Be sure to pass in true for the recursive param.
This did the trick. Problem solved. Thanks for your help.
Emanuel
Hi Emanuel,
Hm, I took another look and it seems I was mistaken, the way you are adding rows with SetCount should be okay. I'm not sure why it's not working for you.
I think your best bet would be to create a small sample project that demonstrates the problem and Submit an incident to Infragistics Developer Support.
Also, you might want to try calling grid.Rows.Refresh(ReloadData) and see if that helps, just as a workaround for now. Be sure to pass in true for the recursive param.
Thank you for your answer, but I have the following questions and comments:
Mike Saltzman"]I'm not sure I follow exactly what you are trying to do here.
I have to show the user a list of parent business objects with their list of children business object. In the previous example:unitate is the parent business object, and it has a list of none, one or more gestiune business objects. When the list is refreshed, I don't want to lose the focus on the current selected row, so I'm using the SetCount on the DataSource to set the new number of rows available. After that I am looping each row to set it's data. The UltraGrid updates itself correctly in the case of the root rows with index different than 0, but fails to do so in the case of the root row with index 0.
Mike Saltzman"]The SetCount method is only intended for use when you are loading the data on-demand.
In the Infragistics help page "Load Data On-Demand"(http://help.infragistics.com/Help/NetAdvantage/NET/2008.1/CLR2.0/html/WinDataSource_Load_Data_on_Demand.html) is mentioned: "The CellDataRequested event is fired when a control bound to the WinDataSource requests value for a cell and WinDataSource doesn't have the cell value". In my case the data is already there.
In the documentation page "Use WinDataSource at Run Time" (http://help.infragistics.com/Help/NetAdvantage/NET/2008.1/CLR2.0/html/WinDataSource_Use_WinDataSource_at_Run_Time.html), which is what I am using the following code snippet can be found:
private void Use_WinDataSource_at_Run_Time_Load( object sender, System.EventArgs e)
private void
object
// structure building code for ultraDataSource -
// not relevant in this case, I've set it in design time
//
not relevant in this case, I've set it in design time
// Set the count on the root rows collection to 2.
this.ultraDataSource1.Rows.SetCount( 2 );
this
UltraDataRow row;
// Initialize rows with data.
// Get the first row.
row = this.ultraDataSource1.Rows[0];
row[ "Col0" ] = "Row 0, Col 0";
row[ "Col1" ] = "Row 0, Col 1";
// Initialize the child rows of the row.
UltraDataRowsCollection childRows = row.GetChildRows( "ChildBand" );
childRows.SetCount( 2 );
childRows[0][ "ChildCol0" ] = "Child Row 0, ChildCol 0";
childRows[0][ "ChildCol1" ] = "Child Row 0, ChildCol 1";
childRows[1][ "ChildCol0" ] = "Child Row 1, ChildCol 0";
childRows[1][ "ChildCol1" ] = "Child Row 1, ChildCol 1";
// Get the second row.
row = this.ultraDataSource1.Rows[1];
row[ "Col0" ] = "Row 1, Col 0";
row[ "Col1" ] = "Row 1, Col 1";
childRows = row.GetChildRows( "ChildBand" );
childRows.SetCount( 1 );
This was the example I studyed before choosing to implement the solution I've presented in the previous post. The SetCount method is being used on the UltraDataSource to set the number of rows which are afterwards filled with data.
Mike Saltzman"]So if you use SetCount, then you have to handle the other events of the UltraDataSource like CellDataRequested.
I have added a CellDataRequested event listener on the UltraDataSource, and, if I completely fill the root rows and the child rows with data, it is never called.
Mike Saltzman"]If you want to manually populate your data source with data, then you should be adding rows using the Add method.
I hate to do a Clear and the Add on the rows collection, because it looks like unneeded work. All I need is to set the new number of rows and set the data for each one of them.
My question is: why the method I'm using works excellent for all the other root rows with child rows in the shown (the number of child rows is raising or shrinking, the UltraGrid it's updating itself well), except for the first root row (in which although the UltraDataSource has the correct number of rows, the UltraGrid it's not changing the number of the children rows). If I enter a new first root row, it gets all the children rows the last first root row had, and the ex first root row, which is now the second one, is working as it should do. The same way of reseting the rows count and filling the data I am using to work with singleband grids and it works perfectly.
I'm not sure I follow exactly what you are trying to do here. The SetCount method is only intended for use when you are loading the data on-demand. So if you use SetCount, then you have to handle the other events of the UltraDataSource like CellDataRequested. See the Million Rows Sample.
If you want to manually populate your data source with data, then you should be adding rows using the Add method.