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

changing dropdown data based on another dropdown within GridView

6 Answers 555 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jerry
Top achievements
Rank 1
Jerry asked on 11 Sep 2013, 03:26 PM
Hi everyone.

I have a radGridView that has two columns that are dropdownlists.  I add these to my grid like this

string sTABS = "select tabid, tabname from tables";
dtTable = GetData(sTABS); //Procedure to get the data back as a datatable
 
GridViewComboBoxColumn tabcol = new GridViewComboBoxColumn();
tabcol.DropDownStyle = RadDropDownStyle.DropDownList;
tabcol.HeaderText = "Table";
tabcol.FieldName = "TABID";
tabcol.DataSource = dtTable;
tabcol.DisplayMember = "TABNAME";
tabcol.ValueMember = "TABID";
tabcol.Width = 150;
gvSetup.Columns.Add(tabcol);
 
string sCOLS = "Select TVID, COLNAME From Cols";
dtCols = GetData(sCOLS); //Procedure to get the data back as a datatable
 
GridViewComboBoxColumn col = new GridViewComboBoxColumn();
col.DropDownStyle = RadDropDownStyle.DropDownList;
col.HeaderText = "Columns";
col.FieldName = "TVID";
col.DataSource = dtCols;
col.DisplayMember = "COLNAME";
col.ValueMember = "TVID";
col.Width = 150;
gvSetup.Columns.Add(col);

I need to find what event and how I can have a user change the table dropdown and repopulate the column dropdown based on the value from the table dropdown?  

Thank you

6 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 16 Sep 2013, 02:01 PM
Hi Jerry,

Please take a look at the following knowledge base article which explains how to implement cascading comboboxes: Cascading ComboBoxes in RadGridView.

Note that you have to bind the drop-down editor to a subset of the data bound to the Columns column.

I hope this helps.

Regards,
Nikolay
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Jerry
Top achievements
Rank 1
answered on 18 Sep 2013, 02:43 PM
Hi Nikolay,

Thank you so much that helped me fix my issue.
0
Azhar
Top achievements
Rank 1
answered on 30 Sep 2014, 09:32 AM
Dear Nikolay,

In the example provided the vegetablesList is having ID from 4,5,6. Which is different from the fruitList.

In database scenario there is a foreign key for defining as fruit or vegetable.[1,2]

Item:
1,"Fruit";
2,"Vegetable";

ItemDetail:
1,1,"Mango";
1,2,"Banana";
1,3,"Pear";
2,1,"Cucumber";
2,2,"Tomato";
2,3."Spinach";

Now in that case the vegetablesList will also have of 1,2,3.

I am successful in displaying the Fruits Or Vegetables in the selection drop down combo box. But when the editor closes it displays Fruit as it also has ID 1.[We have only ValueMember].

How can i tell the grid that Item Detail is 1,1 [Mango]  and not 2,1 [Cucumber]

0
Dimitar
Telerik team
answered on 02 Oct 2014, 12:12 PM
Hello Azhar,

Thank you for writing.

The demo project only demonstrates how such behaviour can be achieved. In this case it uses some sample data which can be easily changed to objects that are containing additional information. However in the sample specific case if you have foods with the same ID there is no way to determine if one is fruit or vegetable. Please note that this is the purpose for the ID and it should be unique for each food in this case. 

I hope this helps.

Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
answered on 28 Sep 2017, 02:24 PM

While your link get's me 99% of the way there. The CellValueChanged event doesn't fire until you move off the cell. So, if my starting values are FoodType = "Fruit" and Food = "Peach", when you change FoodType to "Vegetable", the Food dropdown still shows "Peach", until you click off that CELL. Is there any work around for this? I will continue to look for one.

 

Thanks

0
Dimitar
Telerik team
answered on 29 Sep 2017, 08:30 AM
Hello, Mark,

You can use the ValueChanged event which will be fired when the value in the editor is changed. The following snippet shows how you can get the editor:
private void RadGridView1_ValueChanged(object sender, EventArgs e)
{
    var editor = radGridView1.ActiveEditor as RadDropDownListEditor;
    if (editor != null && radGridView1.CurrentColumn.Name =="Name")
    {
 
    }
}

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Jerry
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Jerry
Top achievements
Rank 1
Azhar
Top achievements
Rank 1
Dimitar
Telerik team
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
Share this question
or