changing dropdown data based on another dropdown within GridView

7 posts, 0 answers
  1. Jerry
    Jerry avatar
    45 posts
    Member since:
    Mar 2012

    Posted 11 Sep 2013 Link to this post

    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
  2. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 16 Sep 2013 Link to this post

    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 >>
  3. Jerry
    Jerry avatar
    45 posts
    Member since:
    Mar 2012

    Posted 18 Sep 2013 Link to this post

    Hi Nikolay,

    Thank you so much that helped me fix my issue.
  4. Azhar
    Azhar avatar
    1 posts
    Member since:
    Feb 2014

    Posted 30 Sep 2014 in reply to Nikolay Link to this post

    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]

  5. Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 02 Oct 2014 Link to this post

    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.
     
  6. Mark
    Mark avatar
    66 posts
    Member since:
    Oct 2014

    Posted 28 Sep in reply to Dimitar Link to this post

    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

  7. Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 29 Sep Link to this post

    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.
Back to Top