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
Hi Alan,
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
Pavan,
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.
Hello Alan,
I'm slowly migrating the control with all server side events with success.
I've a OnRowInitialize event, where I need to set the CssClass for Child band rows. How would I access the RowIslands of a particular row on InitializeRow event? All my child rows intially would be in a collapsed state.
I'm using dataset as the datasource to the WebHierarchicalDataGrid. Pleae help me in iterating thru the child rows and parent rows on server side. Below is the code I'm using at the moment, But everytime i get the parent row count correctly and HasRowIslands as false.
protected void UltraWebGrid_InitializeRow(object sender, RowEventArgs e) { ContainerGridRecord row1 = (ContainerGridRecord)e.Row; foreach (ContainerGridRecord gridRow in budgetingGridTest.UnderlyingGrid.GridView.Rows) { if (gridRow.HasRowIslands) { ContainerGridRecordCollection childRows = gridRow.RowIslands[0].Rows; //If the current row has RowIslands, iterate through row island rows foreach (ContainerGridRecord row in childRows) { CheckBox cb = (CheckBox)row.Items[2].FindControl("CheckBox1"); cb.Checked = true; } } } foreach (GridRecord row in this.budgetingGridTest.UnderlyingGrid.GridView.Rows) { if (row1.HasRowIslands) { } } foreach (GridRecordItem CurrentCell in e.Row.Items) { if (CurrentCell.Row.DataKey.ToString() == "All") { CurrentCell.CssClass = "BoundFieldBG"; } } //if (row.RowIslands.Count > 0) //{ //} }
You may want to make sure the grid binds to all data initially by setting InitialDataBindDepth to -1. There are more details on what this does in the Load On Demand topic.