This is a migrated thread and some comments may be shown as answers.

Getting Childrow Values from RadGridView

3 Answers 238 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 14 Jul 2008, 07:14 PM
I am manually building a radgridview with a childgridview with custom objects but I am not clear on how to retrieve the child rows value on press of a button.  I am adding a decimal column that I want to retrieve the user input.

Below is the code that populated the radgridview.

Thanks.



BindingList<LoadLine> loadLines = new BindingList<LoadLine>();
            BindingList<PartLocation> partLocations = new BindingList<PartLocation>();

GridViewTemplate locationsTemplate = new GridViewTemplate(this.radGridViewLoadDetailLoadLines);
                locationsTemplate.AutoGenerateColumns = false;

                #region Manually Add Columns for Child Table

                GridViewDataColumn columnPartId = new GridViewDataColumn();
                columnPartId.UniqueName = "PartId";
                columnPartId.FieldAlias = "PartId";
                columnPartId.FieldName = "PartId";
                locationsTemplate.Columns.Add(columnPartId);

                GridViewDataColumn columnLocationId = new GridViewDataColumn();
                columnLocationId.UniqueName = "LocationId";
                columnLocationId.FieldAlias = "LocationId";
                columnLocationId.FieldName = "LocationId";
                locationsTemplate.Columns.Add(columnLocationId);

                GridViewDataColumn columnAvailableQty = new GridViewDataColumn();
                columnAvailableQty.UniqueName = "AvailableQty";
                columnAvailableQty.FieldAlias = "AvailableQty";
                columnAvailableQty.FieldName = "AvailableQty";
                locationsTemplate.Columns.Add(columnAvailableQty);

                GridViewDecimalColumn columnQtyToAllocate = new GridViewDecimalColumn();
                columnQtyToAllocate.UniqueName = "QtyToAllocate";
                columnQtyToAllocate.HeaderText = "Qty To Load";
                locationsTemplate.Columns.Add(columnQtyToAllocate);

                #endregion

                locationsTemplate.DataSource = partLocations;
                locationsTemplate.AllowAddNewRow = false;
                locationsTemplate.AllowAutoSizeColumns = true;
                locationsTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

                this.radGridViewLoadDetailLoadLines.MasterGridViewTemplate.ChildGridViewTemplates.Add(locationsTemplate);
                GridViewRelation relation = new GridViewRelation(this.radGridViewLoadDetailLoadLines.MasterGridViewTemplate);
                relation.RelationName = "Load Line Part Locations";
                relation.ParentColumnNames.Add("PartId");
                relation.ChildColumnNames.Add("PartId");
                relation.ChildTemplate = locationsTemplate;
                this.radGridViewLoadDetailLoadLines.Relations.Add(relation);

this.radGridViewLoadDetailLoadLines.DataSource = loadLines;

3 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 14 Jul 2008, 07:32 PM
Basically what I would like to do is loop thru the parent records and get the data entered for each child.

for example:
foreach (GridViewDataRowInfo row in radGridViewLoadDetailLoadLines.Rows) 
   // foreach (child) 
   { 
     //do work get cell value 
   } 


I hope this makes sense.

Thank you.
0
Jack
Telerik team
answered on 15 Jul 2008, 09:19 AM
Hi Michael,

Thank you for this question.

You can iterate through the child rows in RadGridView using the GetChildRows method of the child GridViewTemplate. Consider the code snippet below:

private void radButton1_Click(object sender, EventArgs e) 
    foreach (GridViewDataRowInfo row in this.radGridView1.Rows) 
    { 
        GridViewRowInfo[] childRows = row.ViewTemplate.ChildGridViewTemplates[0].GetChildRows(row); 
        if (childRows != null
        { 
            foreach (GridViewRowInfo childRow in childRows) 
            { 
                // ..  
            } 
        } 
    } 


I hope this helps. Should you have other questions, I will be glad helping you.

Best wishes,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Michael
Top achievements
Rank 1
answered on 15 Jul 2008, 01:16 PM
This is exactly what I was looking for.

Very much appreciated.

Thanks Jack,

Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Jack
Telerik team
Share this question
or