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,
Many thanks for the reply! Sorry if I'm troubling you much..
0546A52EF7F61F69CA29B4B6634A1B420FD68C22 said:How to bind already columns with bands along with the newly created rows to the grid? - Not 100% sure what is meant here, it sounds as though you are appending data to a grid that already contains data. If this is on the initial request, add the rows before you set the data source of the grid. If this is on subsequent requests, how are you persisting the data across post backs? Is that a responsibility of the UserControl? If yes, one of the simplest solutions is to store the data source you are bound to in view state if it support serialization like a DataSet does.
I'm attaching my .cs file herewith, I'm creating the 2 columns and 2 bands from the code behind, Later as you suggested, I've created a dataset with rows and columns and giving it as data source to the gird. But this fails with the error "In order to use load-on-demand DataKeyFields need to be set for each parent Band." I'm not sure what is going wrong here.
While creating bands, I'm adding the datakeys and datamember to the band.
protected void Page_Load(object sender, EventArgs e) { budgetingGridTest.Height = 150; budgetingGridTest.BudgetingYear = 2010; budgetingGridTest.FirstYearToDisplay = 2009; budgetingGridTest.LastActualsMonth = 11; budgetingGridTest.NumberOfYearsToDisplay = NumberOfYearsToDisplay; budgetingGridTest.NumberOfYearsOfMonthlyBasedAmounts = 2; budgetingGridTest.DisplayColumnForFutureYears = true; budgetingGrid2.Height = 150; budgetingGrid2.BudgetingYear = 2010; budgetingGrid2.FirstYearToDisplay = 2009; budgetingGrid2.LastActualsMonth = 11; budgetingGrid2.NumberOfYearsToDisplay = 4; budgetingGrid2.NumberOfYearsOfMonthlyBasedAmounts = 2; // First BudgetingGridModel.Band firstBand = budgetingGridTest.AddNewBand("First", "first"); BudgetingGridModel.Column firstColumn = firstBand.AddNewColumn("First"); firstColumn.OverrideWidth(150); BudgetingGridModel.Band firstBand2 = budgetingGrid2.AddNewBand("First", "first"); BudgetingGridModel.Column firstColumn2 = firstBand2.AddNewColumn("First"); firstColumn2.OverrideWidth(150); // Second BudgetingGridModel.Band secondBand = budgetingGridTest.AddNewBand("Second", "second"); BudgetingGridModel.Column secondColumn = secondBand.AddNewColumn("Second"); secondColumn.OverrideWidth(115); BudgetingGridModel.Band secondBand2 = budgetingGrid2.AddNewBand("Second", "second"); BudgetingGridModel.Column secondColumn2 = secondBand2.AddNewColumn("Second"); secondColumn2.OverrideWidth(115); //Comment BudgetingGridModel.Column commentColumn = budgetingGridTest.AppendNewColumn("Comment", BudgetingGridModel.Column.ColumnTypes.EditableText); commentColumn.OverrideWidth(200); commentColumn.HeaderCaption = "Comment"; BudgetingGridModel.Column commentColumn2 = budgetingGrid2.AppendNewColumn("Comment", BudgetingGridModel.Column.ColumnTypes.EditableText); commentColumn2.OverrideWidth(200); commentColumn2.HeaderCaption = "Comment"; // Delete BudgetingGridModel.Column deleteColumn = budgetingGridTest.AppendNewColumn("Delete", BudgetingGridModel.Column.ColumnTypes.Custom); deleteColumn.OverrideWidth(100); deleteColumn.HeaderCaption = "Delete"; BudgetingGridModel.Column deleteColumn2 = budgetingGrid2.AppendNewColumn("Delete", BudgetingGridModel.Column.ColumnTypes.Custom); deleteColumn2.OverrideWidth(100); deleteColumn2.HeaderCaption = "Delete"; if (ViewState["Initialized"] == null) { budgetingGridTest.CreateStructure(); budgetingGrid2.CreateStructure(); //This is the method we used to create rows andadd it the ultrawebgrid.. / / / first //BudgetingGridModel.Row firstRow = budgetingGridTest.GetOrCreateRow("1", BudgetingGridModel.Row.RowTypes.RollUp, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.LastActualsMonth = 7; // //createdRow.UnderlyingRow.Cells.FromKey("First").Text = "1"; // createdRow.UnderlyingRow.Items.FindItemByKey("First").Text = "1"; // }); //budgetingGridTest.UnderlyingGrid.DataSource = PopulateGrid(); DataTable table = new DataTable(); table.Columns.Add("Dosage", typeof(int)); table.Columns.Add("Drug", typeof(string)); table.Columns.Add("Patient", typeof(string)); table.Columns.Add("Date", typeof(DateTime)); // Here we add five DataRows. table.Rows.Add(25, "Indocin", "David", DateTime.Now); table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now); table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now); table.Rows.Add(21, "Combivent", "Janet", DateTime.Now); table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now); budgetingGridTest.UnderlyingGrid.DataSource = table; budgetingGridTest.UnderlyingGrid.DataBind(); //BudgetingGridModel.Row firstRow2 = budgetingGrid2.GetOrCreateRow("1", BudgetingGridModel.Row.RowTypes.RollUp, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.LastActualsMonth = 7; // createdRow.UnderlyingRow.Items.FindItemByKey("First").Text = "1"; // }); //// second //BudgetingGridModel.Row firstRowChildRow = firstRow.GetOrCreateRow("1.1", BudgetingGridModel.Row.RowTypes.Editable, true, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.UnderlyingRow.Items.FindItemByKey("Second").Text = "1.1"; // }); //firstRow2.GetOrCreateRow("1.1", BudgetingGridModel.Row.RowTypes.Editable, true, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.UnderlyingRow.Items.FindItemByKey("Second").Text = "1.1"; // }); //// first //BudgetingGridModel.Row secondRow = budgetingGridTest.GetOrCreateRow("2", BudgetingGridModel.Row.RowTypes.RollUp, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.UnderlyingRow.Items.FindItemByKey("First").Text = "2"; // }); //BudgetingGridModel.Row secondRow2 = budgetingGrid2.GetOrCreateRow("2", BudgetingGridModel.Row.RowTypes.RollUp, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.UnderlyingRow.Items.FindItemByKey("First").Text = "2"; // }); //// Second //BudgetingGridModel.Row secondRowChildRow = secondRow.GetOrCreateRow("2.1", true, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.UnderlyingRow.Items.FindItemByKey("Second").Text = "2.1 <em>(readonly)</em>"; // }); //firstRowChildRow.AddFutureYearsAmount(12345); //secondRowChildRow.SetMonthlyAmount(2010, 8, 1984); //secondRowChildRow.AddFutureYearsAmount(123456); //secondRowChildRow.SetCellContent("Delete", "<marquee><a href=\"#\">Test to see if HTML markup can be used</a></marquee>"); ViewState["Initialized"] = true; } }
PS : Couldnt attach as I didnt find any link. Request you to kindly guide me on this.
Thanks much!
I've created 2 bands and 2 columns in the above code, But how can I add these already created columns to the data table and bind it to the grid>? How to add the created columns to the data table along with new data rows? I hope my question is clear now.
Thanks!
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.
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.
Thank you for your reply!
As you suggested, I started creating a webhierarchicaldatagrid independently..
I figured out to add columns to the grid with group fields and bound data fields. But the columns are being displayed twice in the grid. Below is my datatable mapping code, Puzzled where i'm going wrong.
Request you to guide me.
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); //} for (int column = 0; column <= band.UnderlyingBand.Columns.Count-1; column++) { DataColumn d = new DataColumn(band.UnderlyingBand.Columns[column].Key); dt.Columns.Add(d); } DataColumn[] PrimaryKeyColumns = new DataColumn[1]; PrimaryKeyColumns[0] = dt.Columns["2009Total"]; dt.PrimaryKey = PrimaryKeyColumns; } DataRow row; for (int i = 0; i <= 18; i++) { row = dt.NewRow(); row[i] = i; row["2009Total"] = 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["2009Total"]; DataColumn childColumn = set.Tables[1].Columns["relation"]; DataRelation relation = new DataRelation("RelationName", parentColumn, childColumn); set.Relations.Add(relation); budgetingGridTest.UnderlyingGrid.DataSource = set; budgetingGridTest.UnderlyingGrid.DataBind();
Code for adding the columns from codebehind method
private void AddColumnsForMonthlyBasedAmountsYears(BudgetingGrid budgetingGrid) { StyleUltraWebGridHeaders h = new StyleUltraWebGridHeaders(); for (int year = budgetingGrid.BudgetingYear; year <= budgetingGrid.LastYearOfMonthlyBasedAmounts; year++) { GroupField monthGroup = new GroupField(); monthGroup.Header.Text = year.ToString(); monthGroup.Header.CssClass = "HeaderCell"; monthGroup.Key = Guid.NewGuid().ToString().Substring(0, 8).ToString(); // Create and add the month columns for (int month = 1; month <= 12; month++) { string monthCellKey = year + "Month" + month; //string monthCellKey = Guid.NewGuid().ToString().Substring(0, 8).ToString(); //UltraGridColumn monthColumn = CreateAmountColumn(monthCellKey); BoundDataField monthColumn = CreateAmountColumn(monthCellKey); // Add the column to all bands foreach (BudgetingGrid.Band band in budgetingGrid.Bands) { band.UnderlyingBand.Columns.Add(monthColumn); } monthColumn.Header.Text = h.GetAbreviatedMonthName(month); monthGroup.Columns.Add(monthColumn); } budgetingGrid.UnderlyingGrid.Columns.Add(monthGroup); // Create and add the year total column string yearCellKey = year + "Total"; //UltraGridColumn yearColumn = CreateAmountColumn(yearCellKey); BoundDataField yearColumn = CreateAmountColumn(yearCellKey); yearColumn.Header.Text = "Total"; // Add the column to all bands foreach (BudgetingGrid.Band band in budgetingGrid.Bands) { band.UnderlyingBand.Columns.Add(yearColumn); } } } private BoundDataField CreateAmountColumn(string key) { //UltraGridColumn amountColumn = new UltraGridColumn(); BoundDataField amountColumn = new BoundDataField(); amountColumn.Key = key; //amountColumn.Header.Text = "TEST"; //amountColumn.DefaultValue = 0; //amountColumn.NullText = "0"; amountColumn.DataType = "System.Decimal"; //amountColumn.DataFormatString = "###,###,###,##0"; return amountColumn; }
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.