Hello,
I am having 2 problems with the WHDG right now.
1. I am trying to define the columns and child columns in c# code at runtime. My data source is a LINQ object with the following structure:
public string PartNo { get; set; } public string PartDesc { get; set; } public string CustomerPartNo { get; set; } public int TotalQty { get; set; }public List<ConsignmentCase> Cases //this contains the child rows
The Cases object looks like this:
public int ID { get; set; } public string PartNo { get; set; } public string CaseNo { get; set; } public DateTime MfgDate { get; set; } public DateTime ExpDate {get;set;} public int Qty { get; set; } public string CustomerPO { get; set; }
I have set AutogenerateColumns and AutoGenerateBands to false
//Here's the markup
<ig:WebHierarchicalDataGrid ID="InventoryGrid" InitialDataBindDepth="1" MaxDataBindDepth="1" DataKeyFields="PartNo" runat="server" Width="100%" OnInitializeRow="InventoryGrid_InitializeRow" AutoGenerateColumns="false" AutoGenerateBands="false" ExpandButton-ImageUrl="~/ig_res/Default/images/expand.gif" ExpandButton-PressedImageUrl="~/ig_res/Default/images/expand_hover.gif" ExpandButton-HoverImageUrl="~/ig_res/Default/images/expand_hover.gif" CollapseButton-ImageUrl="~/ig_res/Default/images/collapse.gif" CollapseButton-HoverImageUrl="~/ig_res/Default/images/collapse_hover.gif" CollapseButton-PressedImageUrl="~/ig_res/Default/images/collapse_hover.gif"> </ig:WebHierarchicalDataGrid>
//Here's the code to build the grid columns
InventoryGrid.Columns.Clear(); InventoryGrid.GridView.Columns.Clear(); InventoryGrid.GridView.ClearDataSource(); InventoryGrid.Visible = true;
InventoryGrid.DataSource = ftsRepository.GetConsignmentInventory(OverrideCompany, txtSearch.Text);
//manually add the columns to the parent level of the hierarchy; // allows us to set the Column Header and width BoundDataField bdf = new BoundDataField(); bdf.DataFieldName = "PartNo"; bdf.Key = "PartNo"; bdf.Header.Text = "Part No."; bdf.Width = 186; InventoryGrid.GridView.Columns.Add(bdf);
bdf = new BoundDataField(); bdf.DataFieldName = "CustomerPartNo"; bdf.Key = "CustomerPartNo"; bdf.Header.Text = "Customer Part No."; bdf.Width = 186; InventoryGrid.GridView.Columns.Add(bdf);
bdf = new BoundDataField(); bdf.DataFieldName = "TotalQty"; bdf.Key = "TotalQty"; bdf.Header.Text = "Quantity"; bdf.Width = 90; InventoryGrid.GridView.Columns.Add(bdf);
bdf = new BoundDataField(); bdf.DataFieldName = "PartDesc"; bdf.Key = "PartDesc"; bdf.Header.Text = "Part Description"; bdf.Width = 336; InventoryGrid.GridView.Columns.Add(bdf);
Band childBand = new Band(); childBand.DataKeyFields = "CaseNo"; childBand.DataMember = "Cases";
childBand.Key = "CaseNo"; InventoryGrid.Bands.Add(childBand);
UnboundCheckBoxField cbf = new UnboundCheckBoxField(); cbf.Key = "ID"; cbf.Width = 25; InventoryGrid.Bands[0].Columns.Add(cbf);
bdf = new BoundDataField();
bdf.Key = "PartNo";
bdf.Header.Text = "Part No"; InventoryGrid.Bands[0].Columns.Add(bdf);
bdf = new BoundDataField(); bdf.Key = "CaseNo"; bdf.Header.Text = "Case No"; InventoryGrid.Bands[0].Columns.Add(bdf);
Event though Autogeneratebands is false, the columns in my child Cases all appear in the child grid, in addition to the 2 child columns i have added. How can I get this to only include the columns that I am specifically adding?
2. When I try to add a Unboundcheckbox field to the Child grid, the checkbox is not editable. How can I enable the checkbox in my c# code?
Thank you,
Steve
Hello Steve,Thank you for using our forum.1. When in the WHDG you set AutogenerateColumns to false, this is valid only for the root grid. In all child band you have to set it also.In your case when you are creating the childBand you have to set childBand. AutogenerateColumns= false.2. To can checkbox be editable you have to enable cell editing feature. You can look at our samples Checkbox Column:http://www.infragistics.com/samples/aspnet/data-grid/checkbox-columnUnbound Checkbox Columnhttp://www.infragistics.com/samples/aspnet/hierarchical-data-grid/unbound-checkbox-column
Please let me know if I can provide any further assistance
Hi Nadia,
Thank you for your help. Number 1 is resolved. I still can't find an example of how to enable the cell editing feature for the unbound checkbox in c# code. Can you help?
The example code you sent was very helpful, thank you! I was able to create the grid with parent and child tables and the submit button executes correctly without an error.
Now I am having a different issue. The checkbox is visible on each child row, but only the first row's checkbox is editable. My code is included below.
Please let me know what I am doing wrong.
Thanks,Steve
private DataSet GetDataSource() { DataSet ds = new DataSet(); ds.Tables.Add(BuildParentTable()); ds.Tables.Add(BuildChildTable()); ds.Relations.Add(ds.Tables[0].Columns["PartNo"], ds.Tables[1].Columns["PartNo"]); return ds; }
private void LoadConsignmentParts() { InventoryGrid.Columns.Clear(); InventoryGrid.GridView.Columns.Clear(); InventoryGrid.GridView.Band.Bands.Clear(); InventoryGrid.GridView.ClearDataSource(); InventoryGrid.Visible = true;
//InventoryGrid.DataSource = ftsRepository.GetConsignmentInventory(OverrideCompany, txtSearch.Text); InventoryGrid.DataSource = GetDataSource();
BoundDataField bdf = new BoundDataField(); bdf.DataFieldName = "PartNo"; bdf.Key = "PartNo"; bdf.Header.Text = "PartNo"; bdf.Width = 186; InventoryGrid.GridView.Columns.Add(bdf);
bdf = new BoundDataField(); bdf.DataFieldName = "CustomerPartNo"; bdf.Key = "CustomerPartNo"; bdf.Header.Text = "CustomerPartNo"; bdf.Width = 186; InventoryGrid.GridView.Columns.Add(bdf);
bdf = new BoundDataField(); bdf.DataFieldName = "TotalQty"; bdf.Key = "TotalQty"; bdf.Header.Text = "Quantity"; bdf.Width = 56; InventoryGrid.GridView.Columns.Add(bdf);
bdf = new BoundDataField(); bdf.DataFieldName = "PartDesc"; bdf.Key = "PartDesc"; bdf.Header.Text = "PartDesc"; bdf.Width = 256; InventoryGrid.GridView.Columns.Add(bdf);
Band childBand = new Band(); childBand.DataKeyFields = "PartNo"; childBand.DataMember = "ConsignmentCases";
childBand.Key = "CaseNo";
InventoryGrid.Bands.Add(childBand); //add editing behaviors to allow the checkbox to be checked/unchecked EditingCore editingCoreBehavior = InventoryGrid.Bands[0].Behaviors.CreateBehavior<EditingCore>(); InventoryGrid.GridView.Behaviors.Add(editingCoreBehavior);
CellEditing cellEditingBehavior = editingCoreBehavior.Behaviors.CreateBehavior<CellEditing>(); InventoryGrid.GridView.Behaviors.EditingCore.Behaviors.Add(cellEditingBehavior);
cellEditingBehavior.Enabled = true;
UnboundCheckBoxField cbf = new UnboundCheckBoxField(); cbf.Key = "ID1"; cbf.Width = 25; childBand.Columns.Add(cbf);
childBand.AutoGenerateColumns = false;
bdf = new BoundDataField(); bdf.Key = "PartNo"; bdf.Header.Text = "PartNo"; bdf.Width = 150; childBand.Columns.Add(bdf);
bdf = new BoundDataField(); bdf.Key = "CaseNo"; bdf.Header.Text = "CaseNo"; bdf.Width = 120; childBand.Columns.Add(bdf);
bdf = new BoundDataField(); bdf.Key = "MfgDate"; bdf.Header.Text = "Mfg.Date"; bdf.Width = 82; childBand.Columns.Add(bdf);
bdf = new BoundDataField(); bdf.Key = "ExpDate"; bdf.Header.Text = "Exp.Date"; bdf.Width = 82; childBand.Columns.Add(bdf);
bdf = new BoundDataField(); bdf.Key = "Qty"; bdf.Header.Text = "Case Qty."; bdf.Width = 72; childBand.Columns.Add(bdf);
bdf = new BoundDataField(); bdf.Key = "CustomerPO"; bdf.Header.Text = "Customer PO#"; bdf.Width = 130; childBand.Columns.Add(bdf);
bdf = new BoundDataField(); bdf.Key = "MfpTrackNo"; bdf.Header.Text = "MFP Track#"; bdf.Width = 100; childBand.Columns.Add(bdf);
// do the databind InventoryGrid.DataBind();
if (InventoryGrid.Rows.Count < 1) { InventoryGrid.Visible = false; } }
private DataTable BuildParentTable() { System.Data.DataTable table = new DataTable("ConsignmentParts"); DataColumn column; DataRow row;
column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "PartNo"; column.AutoIncrement = false; column.Caption = "PartNo"; column.ReadOnly = false; column.Unique = false; table.Columns.Add(column);
column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "CustomerPartNo"; column.AutoIncrement = false; column.Caption = "CustomerPartNo"; column.ReadOnly = false; column.Unique = false; table.Columns.Add(column);
column = new DataColumn(); column.DataType = System.Type.GetType("System.Int32"); column.ColumnName = "TotalQty"; column.AutoIncrement = false; column.Caption = "TotalQty"; column.ReadOnly = false; column.Unique = false; table.Columns.Add(column);
column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "PartDesc"; column.AutoIncrement = false; column.Caption = "PartDesc"; column.ReadOnly = false; column.Unique = false; table.Columns.Add(column);
DataColumn[] PrimaryKeyColumns = new DataColumn[1]; PrimaryKeyColumns[0] = table.Columns["PartNo"]; table.PrimaryKey = PrimaryKeyColumns;
List<ConsignmentPart> parts = ftsRepository.GetConsignmentParts(OverrideCompany, txtSearch.Text); foreach (var part in parts) { row = table.NewRow();
row["PartNo"] = part.PartNo; row["CustomerPartNo"] = part.CustomerPartNo; row["TotalQty"] = part.TotalQty; row["PartDesc"] = part.PartDesc;
table.Rows.Add(row); } return table;
}
private DataTable BuildChildTable() { System.Data.DataTable table = new DataTable("ConsignmentCases"); DataColumn column; DataRow row;
column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "CaseNo"; column.AutoIncrement = false; column.Caption = "CaseNo"; column.ReadOnly = false; column.Unique = false; table.Columns.Add(column);
column = new DataColumn(); column.DataType = System.Type.GetType("System.DateTime"); column.ColumnName = "MfgDate"; column.AutoIncrement = false; column.Caption = "MfgDate"; column.ReadOnly = false; column.Unique = false; table.Columns.Add(column);
column = new DataColumn(); column.DataType = System.Type.GetType("System.DateTime"); column.ColumnName = "ExpDate"; column.AutoIncrement = false; column.Caption = "ExpDate"; column.ReadOnly = false; column.Unique = false; table.Columns.Add(column);
column = new DataColumn(); column.DataType = System.Type.GetType("System.Int32"); column.ColumnName = "Qty"; column.AutoIncrement = false; column.Caption = "Qty"; column.ReadOnly = false; column.Unique = false; table.Columns.Add(column);
column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "CustomerPO"; column.AutoIncrement = false; column.Caption = "CustomerPO"; column.ReadOnly = false; column.Unique = false; table.Columns.Add(column);
column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "MfpTrackNo"; column.AutoIncrement = false; column.Caption = "MfpTrackNo"; column.ReadOnly = false; column.Unique = false; table.Columns.Add(column);
DataColumn[] PrimaryKeyColumns = new DataColumn[1]; PrimaryKeyColumns[0] = table.Columns["CaseNo"]; table.PrimaryKey = PrimaryKeyColumns;
List<ConsignmentCase> cases = ftsRepository.GetConsignmentCases(OverrideCompany, txtSearch.Text); foreach (var cs in cases) { row = table.NewRow();
row["PartNo"] = cs.PartNo; row["CaseNo"] = cs.CaseNo; row["Qty"] = cs.Qty; row["MfgDate"] = cs.MfgDate; row["ExpDate"] = cs.ExpDate; row["CustomerPO"] = cs.CustomerPO; row["MfpTrackNo"] = cs.MfpTrackNo;
Hi Steve,
I cannot reproduce the issue that you are seeing.
Can you reproduce this in the sample which I send to you?
If you wand just to be able to check the checkbox in the child band you do not need to add the editing behavior in the GridView, you can add it in the childBand and then the editing will be enabled only in the child.
You can use:
childBand.Behaviors.Add(editingCoreBehavior);
childBand.Behaviors.EditingCore.Behaviors.Add(cellEditingBehavior);
Instead of:
InventoryGrid.GridView.Behaviors.Add(editingCoreBehavior);
InventoryGrid.GridView.Behaviors.EditingCore.Behaviors.Add(cellEditingBehavior);
If you want the editing behavior to be enabled in both child and parent you have to set EnableInheritance to true for editingCoreBehavior and cellEditingBehavior.
Please let me know if I can provide any further assistance.
Thank you Nadia, your sample program is working correctly. I need to go through and compare both and figure out what are the differences. I will keep you posted.
I have this working now. I had set the incorrect column name on the child table as the DataKeyField.
Thank you very much for all your help.
Thank you for your replies. Glad you were able to resolve the issue.