Hello,
I need to have 2 bands for my ultraWinGrid layout. In UltraGrid designer I added band[1] as a child for band[0]. I put ViewStyle property to MultiBand. But on InitializeLayout event I have only one band in e.Layout.Bands collection. What should I add in order to get the second band? (and I need to create the second band at design time, not at run time).
Thank you
Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn1 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("Band 1");
Infragistics.Win.UltraWinGrid.UltraGridBand ultraGridBand2 = new Infragistics.Win.UltraWinGrid.UltraGridBand("Band 1", 0);
this.ugRC.DataSource = this.ultraDataSource1;
ultraGridBand2.MinRows = 1;
this.ugRC.DisplayLayout.BandsSerializer.Add(ultraGridBand2);
this.ugRC.DisplayLayout.Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.Yes;
this.ugRC.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.ugRC_InitializeLayout);
You cannot add bands to the grid. The grid bands come from the data source. The BandSerializer is intended for internal use by the grid only, you should never use this class in your code.
If you are using an UltraDataSource, then you should be adding the bands and setting up the column in the UltraDataSource and then just bind it to the grid.
Thank you for the answer. Could you refer me to some example how to do this? Thanks.
Well, I'm not entirely sure if there are samples that add bands to the UltraDataSource in code. But if there are, they would be in th sample folder under UltraDataSource.
You could set up your UltraDataSource at design-time using the designer if you want. That might be easier.
The code isn't very complicated, though. There's a Band property on the UltraDataSource that represents the root band. You can add columns via the Columns collection and child bands via the ChildBands collection.
I have a question about binding multiple bands to a wingrid.
I have the following data structure:
3 bands of data (datatables within a dataset really) all with the exact same columns. For simplicity, I'll call them Parent_Band, Child_Band and Other_Band. As you might guess, the Child_Band is a sub-band of the Parent_Band. I established a data relation within my dataset between these two tables, and they are displaying properly when the dataset is bound to the grid. The parent rows are displaying and have expansion indicators if there are child rows. The child rows are displayed beneath the appropriate parent row.
My problem is that I want to then display all the rows from the Other_Band at the bottom of the grid. Although, this band has the same columns, it should have no "relation" to the other bands and the rows should display as "peers" of the Parent Band. They would never have a child band.
I attempted to accomplish this by adding a third table to the dataset and hoping that they would show up somewhere in the grid, but the records from the Other_Band don't display at all. The other bands continue to display correctly.
Any advice would be greatly appreciated.
Thanks so much,
Steve
Hi Steve,
The grid cannot display sibling bands at the root level. You can have sibling child bands. So one row in the grid can display multiple sets of child bands from different tables. But the root level of the grid can only have a single data source.
So you have a couple of options. You could create another table in your DataSet with two rows and then arrange it such that all of the rows in Parent_Table are under one row and all of the rows in Other_Table are under the other row.
Another option would be to use UltraWinTree instead of UltraWinGrid. The tree lacks some of the features of the grid, like summaries and filtering. But it's a little more flexible in terms of the data structure. You would still need two rows (nodes) at the root level to divide up the Parent_Table and Other_Table data. But these rows would not need to be part of the data structure, you could just add a couple of nodes to the tree and then bind their child nodes to different tables.
Hi Mike,
I have an ultragrid with 3 bands defined, and all column headers etc for the bands are set up using the designer. I retrieve 3 datatables, add them to a dataset, add parent-child relations and bind them to the grid. All columns in the grid are unbound.
My problem is that only the first band retains the designer-generated column settings, the second and third do not - columns hidden in the designer are shown, and the column headers are the column names from the datatable.
I could write code to manually set up the 2nd and 3rd bands, but is there a way for the grid to retain and bind the columns that have already been set up in the designer?
Thanks
Deon
Hi Deon,
The most common cause of a problem like this is the Band Keys. When you set up your bands and columns at design-time, you must make sure that the key of each band matches the key of the data source you are assigning at run-time. The key of a child band is the name of the Relationship in the DataSet, not the table.
What I would do is go into the InitializeLayout event of your grid and loop through the band and the write out the Key of each band in the collection. Then go into the grid designer and make sure your design-time structure is using the same keys.