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

Hierarchical Data and Combo Boxes

7 Answers 117 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Albert
Top achievements
Rank 1
Albert asked on 05 Nov 2009, 02:49 PM

Using a GridView control to bind to Hierarchical Data programmatically.  One of the columns in the Child Template  is a Combo Box. One of the requirements is that the items listed in the combo box are dependent on a value from a Column in the Parent row.

 

For example, if a Column named KitNumber  in the Parent row has a value of  12345 on editing the child row, the combo box should only display the PartNumbers that are relevant to the KitNumber.  Sounds simple enough but I have not been able to figure this out using the GridView control.  Is this possible?

Any suggestions greatly appreciated.

7 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 11 Nov 2009, 02:24 PM
Hi Code7,

Thank you for writing.

You can implement the desired behavior by changing the editor for a chosen column in child view. You can get its parent row through GridViewInfo.ParentRow property and use any cell values for condition. Please, consider the following code as example:
void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
    RadComboBoxEditor editor = this.radGridView1.ActiveEditor as RadComboBoxEditor;
    if (editor != null)
    {
        RadComboBoxEditorElement editorElement = editor.EditorElement as RadComboBoxEditorElement;
 
        GridViewRowInfo parentRow = this.radGridView1.CurrentRow.GridViewInfo.ParentRow;
 
        if (parentRow != null)
        {
            object cellValue = parentRow.Cells["DependColumn"].Value;
 
            if ((int)cellValue == 1)
            {
                editorElement.DataSource = new BindingList<String>() { "Item1", "Item2" };
            }
            else if ((int)cellValue == 2)
            {
                editorElement.DataSource = new BindingList<String>() { "Item3", "Item4", "Item5" };
            }
            else
            {
                editorElement.DataSource = null;
            }
        }
    }
}
 
void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
{
    GridViewColumn currentColumn = this.radGridView1.CurrentColumn;
    if (currentColumn != null && ((GridViewTextBoxColumn)currentColumn).UniqueName.Equals("CustomColumn"))
    {
        e.EditorType = typeof(RadComboBoxEditor);
    }
}
 
private void Form1_Load(object sender, EventArgs e)
{
    GridViewTextBoxColumn column = new GridViewTextBoxColumn();
    column.UniqueName = "CustomColumn";
    this.radGridView1.MasterGridViewTemplate.ChildGridViewTemplates[0].Columns.Add(column);
}

Do not hesitate to contact me again if you have any other questions.

Regards,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Albert
Top achievements
Rank 1
answered on 11 Nov 2009, 02:42 PM
Thanks Martin. I have implemented this approach and have expereinced no other issues.

Thanks again!
0
Albert
Top achievements
Rank 1
answered on 11 Nov 2009, 03:03 PM
Say Martin...on another issue...Is it possible to cancel the row dropdown for the Childrow? So that if there are no childrows for a row don't show the childrow.

Thanks,
0
Martin Vasilev
Telerik team
answered on 16 Nov 2009, 05:17 PM
Hello Code7,

Thank you for getting back to me.

You can easily implement this by using the ChildViewExpanding event. Please take a look to the following code snippet:
void radGridView1_ChildViewExpanding(object sender, ChildViewExpandingEventArgs e)
{
    GridViewRowInfo[] rows = e.ParentRow.ViewTemplate.ChildGridViewTemplates[0].GetChildRows(e.ParentRow);
    if (rows == null || rows.Length <= 0)
    {
        e.Cancel = true;
    }
}

Write me back if you have any other questions.

All the best,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Albert
Top achievements
Rank 1
answered on 16 Nov 2009, 08:25 PM
Excellent. That worked.
0
Jeff
Top achievements
Rank 1
answered on 14 Mar 2014, 02:16 AM
This doesn't seem to work anymore. Can anyone point me to documentation on this?
0
Stefan
Telerik team
answered on 14 Mar 2014, 04:59 PM
We sure can. Here is a link to a KB with an example of this: http://www.telerik.com/support/kb/winforms/gridview/details/cascading-comboboxes-in-radgridview.

I hope this helps.

Regards,
Stefan
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
GridView
Asked by
Albert
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Albert
Top achievements
Rank 1
Jeff
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or