Click here to Skip to main content
15,886,622 members
Articles / Silverlight / Silverlight5
Tip/Trick

[Silverlight] Work with Cascading Drop-down Lists in the Telerik Gridview Control

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
23 Aug 2012CPOL1 min read 40.2K   297   4   3
Work with Cascading Drop-down Lists in the Telerik Gridview Control

This article appears in the Third Party Products and Tools section. Articles in this section are for the members only and must not be used to promote or advertise products in any way, shape or form. Please report any spam or advertising.

Introduction

How to work with cascading drop-down lists in the Telerik gridview control?

The Solution

I am explaining how to work with cascading drop-down lists in the Telerik gridview control. The overall approach is pretty much the same. To review, when you're working with cascading DropDownList controls, you need to perform these tasks:

  • Populate each of the DropDownList controls.
  • Pre-select the appropriate value in each list to match what's currently in the data.
  • When the user selects a new value in the master dropdown, repopulate the detail dropdown with a new set of dependent values.

Here information about the schema of the tables is involved in this exercise.

Here you go:

Table: City (ID,Name,ContinentCodel)

Table: Continent(Code,Name)

As I say, you can do this in the GridView control in a way similar, but not identical to how you do it in Page. Let's say you have a grid that looks like this in normal mode:

XML
<telerik:radgridview x:name="radGridView" autogeneratecolumns="True">
</telerik:radgridview>

And looks like this:

Image 1

When configuring columns that time set AutoGenerateColumns="False" and add columns like:

XML
<telerik:radgridview.columns>
        <telerik:gridviewcomboboxcolumn datamemberbinding="
        {Binding ContinentCode, Mode=TwoWay}" header="Continent"
        displaymemberpath="Name" selectedvaluememberpath="Code">
        <telerik:gridviewcomboboxcolumn itemssourcebinding="
        {Binding AvailableCountries}" datamemberbinding="{Binding CountryID}"
        header="Country" displaymemberpath="Name"
        selectedvaluememberpath="ID" width="400">
    </telerik:gridviewcomboboxcolumn></telerik:gridviewcomboboxcolumn>
    </telerik:radgridview.columns>

When Continent changes that time set country using this code: In Continent selection, changed event looks like: Attached event in MainPage Constructor like:

C#
this.AddHandler(RadComboBox.SelectionChangedEvent, 
new Telerik.Windows.Controls.SelectionChangedEventHandler(comboSelectionChanged));

Selection changed event:

C#
void comboSelectionChanged(object sender, RadRoutedEventArgs args)
        {
            RadComboBox comboBox = (RadComboBox)args.OriginalSource;
            
            if (comboBox.SelectedValue==null 
                || comboBox.SelectedValuePath != "Code")
                return;
            
            Location location = comboBox.DataContext as Location;
            location.ContinentCode = (string)comboBox.SelectedValue;
        }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHow do i bind a telerik radgrid Griddropdowncolumn with database values? Pin
Alesha Mary Milred Fernandes29-Apr-14 5:15
Alesha Mary Milred Fernandes29-Apr-14 5:15 
GeneralMy vote of 5 Pin
Christian Amado23-Aug-12 7:10
professionalChristian Amado23-Aug-12 7:10 
GeneralRe: My vote of 5 Pin
Savalia Manoj M26-Aug-12 17:15
Savalia Manoj M26-Aug-12 17:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.