Hi All,
Could anyone please help me when to use GridRecordCollection and GridRecordItemCollection? I'm using Infragistics 2012.2 to create a webhierarchialdatagrid dynamically as a usercontrol and shall be using this user control in some other pages.
What is the equivalent of UltraGridRow of UltraWebGrid in WebHierarchialDataGrid? Should I use GridRecord or GridRecordItem? Kindly clarify..
Hello Pavan,
If you are looking for a comparison or equivalence I will suggest taking a look in this topics:
Migrating from UltraWebGrid to WebDataGrid and WebHierarchicalDataGrid
UltraWebGrid to WebDataGrid Migration
Furthermore GridRecord is a record or row in the WebDataGrid control, GridRecordItem represents a record item or cell in the WebDataGrid control. The WebHierarchicalDataGrid control is built upon WebDataGrid. The WebHierarchcalDataGrid creates a collection of ContainerGrid objects to display the different hierarchical views. These objects can have child ContainerGrid objects of their own. You can access a row’s child ContainerGrid objects by using the ContainerGridRecord. For more information take a look at the help topic:
https://www.infragistics.com/help/aspnet/webhierarchicaldatagrid-about-webhierarchicaldatagrid
Hello Nick,
Thank you for your prompt response!
Let me put my futher questions wrt UltraWebGrid migration to WebHierarchialDataGrid. I'm using below members in my project to create Rows and Row Items with UltraWebGrid currently. How do I replace these with WebHierarchialdDataGrid members? Please guide me on this..
//Rows collection of UltraWebGrid
RowsCollection ChildrenUnderlyingRows { get; }
//Underlying Row
private UltraGridRow underlyingRow;
// Create the underlying row - UltraWebGrid Row creation UltraGridRow childUnderlyingRow = new UltraGridRow();childUnderlyingRow.Key = key;
//To read a cell from the row
UltraGridCell cellToUpdate = underlyingRow.Cells.FromKey(cellKey);
I've replaced the above methods with below ones:
//RowsCollection has been modified with ContainerGridRecordCollection.
ContainerGridRecordCollection ChildrenUnderlyingRows { get; }
//UltraGridRow has been replaced with ContainerGridRecord
private ContainerGridRecord underlyingRow;
//To read a cell from the grid, replaced it with GridRecordItem
GridRecordItem cellToUpdate = underlyingRow.Items.FindItemByKey(cellKey);
But for this snippet, I'm not able to understand and find a replacement.
Are Key and Datakey one and the same? If you want I shall zip the file and attach with this thread.
Kindly guide me on this migration.
Thanks,
Pavan.P
Pavan,
It would appear that the AddNewBand and AddNewColumn methods are part of your framework so it is difficult to understand what is expected from these without the code for them.
As far as adding Columns to a DataTable, you would just add a DataColumn to the Columns collection of the DataTable. For adding rows, you simply add rows to the DataTable using the Rows collection. All of this should be done before setting the DataSource of the WebDataGrid ideally.
The Data Binding topic for the WebHierarchicalDataGrid has some details on the DataKeyFields property. Since it isn't set in the code provided, you may just need to set it to the primary key of the DataTable. Note that for hierarchical data there should be a key field in the parent and you would be setting the DataKeyFields property to the key of that Column in the parent DataTable.
On attaching files, use Insert -> Insert image/video/file at the bottom of the editor when typing your post or reply.
Let me know if you have any questions.
Hi Alan,
I was able to figure out the columns and rows binding to a datatable and adding relations then binding the grid control. But, now I'm confused with Bands and Columns and couldnt achieve the actual functionality of the user control. We have generic methods in the user control to create bands, columns, group fields. I want to display my user control just like one in the attached image.(This was using UltraWebGrid).
How can I understand and implement completely Bands, When to add columns to bands, GroupFields etc. I'm also attaching the respective AddNewBand and AddNewColumn methods code for your pursuance.
In order to display the grid in above structure, How should i create bands and columns and groupfields(ColumnHeaders)
-- UnderlyingBand is a member of the user control which consists of Infragistics Band. This is the logic to create a band from codebehind.
private Infragistics.Web.UI.GridControls.Band AddNewUnderlyingBand(string key) { Infragistics.Web.UI.GridControls.Band underlyingBand; // Special case when adding the first band in an UltraWebGrid: // the band already exists as the first band in the underlying grid //As this behaviour is different in WebHierarchicalDataGrid, Removed this logic //if (bands.Count == 0) //{ // //underlyingBand.ColHeadersVisible = ShowMarginInfo.Yes; // underlyingBand = underlyingGrid.Bands[0]; // underlyingBand.ShowHeader = true; //} //else //{ // // Check if underlying band already exists // //underlyingBand = underlyingGrid.Bands.FromKey(key); // underlyingBand = (Infragistics.Web.UI.GridControls.Band)underlyingGrid.Bands.FindByDataMember(key); // if (underlyingBand == null) // { // underlyingBand = new Infragistics.Web.UI.GridControls.Band(); // underlyingGrid.Bands.Add(underlyingBand); // } //} underlyingBand = (Infragistics.Web.UI.GridControls.Band)underlyingGrid.Bands.FindByDataMember(key); if (underlyingBand == null) { underlyingBand = new Infragistics.Web.UI.GridControls.Band(); underlyingBand.DataKeyFields = key; underlyingBand.DataMember = key; underlyingGrid.Bands.Add(underlyingBand); } return underlyingBand; }
UnderlyingColumn is a BoundDataField and a member of the user control. Below has the logic of creating a new column,
/// <summary> /// Adds a new column to the underlying band. /// </summary> /// <returns>The new column.</returns> private BoundDataField AddNewUnderlyingColumn(string key) { BoundDataField underlyingColumn = null; // Check if the column was already added first //underlyingColumn = underlyingBand.Columns.FromKey(key); underlyingColumn = (BoundDataField)underlyingBand.Columns.FromKey(key); bool columnAlreadyExists = underlyingColumn != null; if (!columnAlreadyExists) { // Create the underlying column underlyingColumn = new BoundDataField(); underlyingColumn.Key = key; // Add it to the underlying band //underlyingBand.Columns.Add(underlyingColumn); underlyingBand.Columns.Add(underlyingColumn); } return underlyingColumn; }
Logic to create DataColumns and DataRows and binding them to the grid is as below. Here in the below logic, I was not able to iterate thru the created Bands, Because I;ve created 2 bands and added 2 columns to the bands first set of columns with keys are being added to data columns, But when i try iterating the second band columns I'm getting unique keyfield error as the keys are same. How to set the Keys for a column?
DataSet set = new DataSet(); DataTable dt = new DataTable(); //foreach (Peats.Library.Web.UI.BudgetingGrid.Model.BudgetingGrid.Band band in budgetingGridTest.Bands) //{ int k = budgetingGridTest.UnderlyingGrid.Bands[0].Columns.Count; int l = budgetingGridTest.UnderlyingGrid.Bands[1].Columns.Count; for(int i=0; i<=k-1; i++) { DataColumn d = new DataColumn(budgetingGridTest.UnderlyingGrid.Bands[0].Columns[i].Key); dt.Columns.Add(d); } DataColumn[] PrimaryKeyColumns = new DataColumn[1]; PrimaryKeyColumns[0] = dt.Columns["First"]; dt.PrimaryKey = PrimaryKeyColumns; //} DataRow row; for (int i = 0; i <= 19; i++) { row = dt.NewRow(); row[i] = i; row["First"] = i; //row["Second"] = "Item " + i; dt.Rows.Add(row); } set.Tables.Add(dt); //Add two tables //set.Tables.Add(BuildTable("Parent")); set.Tables.Add(BuildChildTable("Child")); //Create relations DataColumn parentColumn = set.Tables[0].Columns["First"]; DataColumn childColumn = set.Tables[1].Columns["relation"]; DataRelation relation = new DataRelation("RelationName", parentColumn, childColumn); set.Relations.Add(relation); budgetingGridTest.UnderlyingGrid.DataSource = set;
I've also added the model classes that I recently upgraded the members with Infragistics 2012.2 WebHierarchicalDataGrid members. Would you please suggest on this as well please.Models.zip
Request you to kindly help me on this.
Good morning!
Did you get a chance to look into it? Currently my usercontrol is being dsiplayed as below, But it should actually be displayed as attached in the above post
.
I guess, I'm missing something to add BoundDataFileds to the GroupFileds and adding again GroupFileds to the WebHierarchicalDataGrid Columns in the models project.
Your help would really be greatly appreciated.. Please guide me to achieve the above post like grid.
Thanks again
It appears as though you are doing aggregations of data, would it be better to just use a pivot grid in the application which has that functionality already built in? Would the igPivotGrid better meet your needs for a control in the UI?
As far as looking to what is happening with your usercontrol, it would help to have a running example that can be debugged, as well as what specifically isn't working as you expect in the sample. As far as how to set up the grid if using the WebHierarchicalDataGrid, from the screen shot it appears that you would set up a DataTable with the following columns:
Then add all of the data to that DataTable to represent what is visible in the screen shot.
Note that this doesn't take into account the children as they aren't expanded out so I don't know what data they represent. There would be additional steps to set up Multi-Column headers for:
I recommend working with the WebHierarchicalDataGrid in an isolated sample to create the view that you need and then see how you can use that within your budgeting wrapper.
My apologies for too many posts Alan, We actually need to upgrade this one and ship to the client and thats the reason I'm frequntly posting, Hope you understand./
Below is the attached old grid implementation screenshot. I'm trying to achieve the same functionality
1. When I click on the left hand side expand button of 1, I'm able to see all the cells with 0's. The same thing I'm trying to achieve with the WebHierarchicalDataGrid and the result is as in the below image.
If you look at the New image, there are few problems;
1. I could see the extra columns after "LifeSpan (GroupField) /Total (BoundDataField)". I dont know why they are being bound to the grid.
2. How would I exapnd the row and create rows temporarily as in the parent row with all 0's (refer to old grid img)
I've already copied the code sinppets of creating the bound data fileds, adding them to group filed and adding back to Grid columns and bands.
Would you please let me know the structure for creating the grid as attached in the first image. I feel my datatable part is not correct..
I'm sorry as I could not give you a working example, But to be very specific, I listed all of them above.
Request you to kindly guide me on this.
PS: Attaching Grid control code behind, Class for creation of Columns.
Files.zip
Thanks
Assuming that the DataSet is set up correctly and all the data is present in the DataSet before binding the grid to data, I don't see what would cause some data to show and some not to show and to look into this I will need a sample that I can debug from you.
On the creation of the extra columns, verify that you have AutoGenerateColumns set to false and that you are only adding the columns a single time in your code.
If you would like help debugging what is happening, please isolate the behavior into a sample that I can run.
I was able to bind the datagrid in the user control and binding part is pretty good and rendered correctly. But when i try to iterate thru the rows of WebHierarchicalDataGrid, it is always returning null in the codebehind. Below is the snippet I'm using to iterate the rows.
Note: I've parent row of the webhierarchicaldatagrid and a child band to it.
foreach (gridrecord firstlevelrow in budgetinggridtest.underlyinggrid.gridview.rows) { foreach (gridrecorditem secondlevelrow in firstlevelrow.items) { for (int monthindex = 1; monthindex <= 12; monthindex++) { //object cellvalue = secondlevelrow.items.finditembykey(2010 + "month" + monthindex).value; object cellvalue = secondlevelrow.row.items.finditembykey(2019 + "month" + monthindex).value; decimal amount = cellvalue == null ? 0 : (decimal)cellvalue; } } } int rows = rec.RowIslands[0].Rows.Count; for (int i = 0; i < rows; i++) { ContainerGridRecord recrows = rec.RowIslands[0].Rows[i]; }
Both the above methods are always null rows while iterating thru. Please help me on this.
From the code provided it isn't clear what specifically is null so I don't know what might be happening.
Is there a reason that you are looping through the grid rather than the DataSet to get the values? I ask because if the data is in the DataSet, you should just get it from the DataSet and not use the grid at all for retrieving the values.
Thanks for providing your support and guidance in migrating the user control to Infragistics 2012.2. Below is the migrated user control being rendered perfectly in a dynamic fashion.
The code I posted in the above thread runs when I click on the Parse Grid button, It just iterartes thru the Rows of the grid to make sure all of the rows bound to the grid are accessible with their respective Row values. As you said, this may not be required as the data is already present in the dataset.
But, In my user control, I also have UltraWebGridRows related logic to parse, create rows from the codebehind. I know that we cannot achieve Row creation from the backend for WebHierarchicalDataGrid, Is there a way to just get the values of the bound grid to do any CRUD operations? Thats the reason I'm asking you specifically about how to iterate thru the rows of the Grid.
I've a property in my class like this.
public ContainerGridRecordCollection ChildrenUnderlyingRows { get { return this.underlyingGrid.GridView.Rows; } }
I also wanted to confirm with you, How to add another set of rows and columns with a button click? Like, in the above grid control you are able to see 2010 year with all 12 months. On a button click event, I want to add 2011, 2012 and 2013 years with some dummy row data.
Please suggest how to handle the dataset methods dynamically in a generic way.
Thanks!
It sounds as though the expectation of the UserControl/grid is that it would store changes to the data as it is edited and then act on the click of a button to persist the data to a database or somewhere else. Assuming that you are allowing editing in the grid, I would recommend that you do the following:
You may even be able to use AutoCrud on the EditingCore behavior to have the grid automatically update the DataSet.
Those changes should allow you to update the grid by updating the DataSet. This would be a good time to refactor the UserControl to expose and interface that isn't dependent on the control used within.
Note that a few updates back you mentioned that you need to ship this to your client. I would advise against rushing through the migration process if you are close to a release. Is there a reason why this needs to be done before you ship? Could you use the UltraWebGrid for this release and plan this work for the next release if you are close to a deadline? The classic control migration guide does provide an approach to upgrade an application to the current volume and continue to use the UltraWebGrid or other classic controls while you are working on the upgrade.