Cascading ComboBoxes in RadGridView

16 posts, 0 answers
  1. Nicholas
    Nicholas avatar
    2 posts
    Member since:
    Dec 2007

    Posted 03 Nov 2009 Link to this post

    I need to create a gridview (winforms) that has two comboboxes where one of the comboboxes' available values are determined by the selection in the first combobox. This seems straightforward but I have run into problems with all the approaches I have tried so far.

    I tried the following:
    1) In the Cell Value Changed event I tried rebinding the  dependent combobox in the based on the selection in the first. The problem that I encounter is that while the combobox is is rebound with the data I am looking for it rebinds the combobox in all of the rows in the grid blanking out selections whose value is no longer one of the combobox values.

    2) I also tried capturing the cell formatting event and adding a new RadComboBoxElement to the cell and populating the the combobox element by adding items to it.  While this does work, the grid's theme doesn't flow through and the grid appears be acting buggy. I've run into a problem when populating this combobox element when it is scrolled off the screen (row isnt visible because the user has to scroll to see it). When part of a row is scrolled off the screen the combobox is painted half in the grid and half on top of the horizantal scroll bar which doesn't look professional. This approach also yields a combobox that has a different look and feel than the other comboboxs in the grid because it doesnt have a distinct edit mode, its always in edit mode, always shows the drop down arrow image.

    Is there any way to do this? I need to populate the values of one combobox based on the selection of another combobox in a RadGridView. At this point I'm becoming very frustrated with these components.
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 06 Nov 2009 Link to this post

    Hi Nicholas,

    You can change the data source by handling CellBeginEdit event. Please consider the code below:  

    void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
    {
        GridViewLookUpColumn column = this.radGridView1.CurrentColumn as GridViewLookUpColumn;
        if (column != null)
        {
            if ((int)this.radGridView1.CurrentRow.Cells["Value"].Value > 5)
            {
                column.DataSource = table1;
            }
            else
            {
                column.DataSource = table2;
            }
        }
    }

    However, you should handle CellFormatting event to set the correct cell value:

    void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridComboBoxCellElement cell = e.CellElement as GridComboBoxCellElement;
        if (cell != null)
        {
            if ((int)e.CellElement.RowInfo.Cells["Value"].Value > 5)
            {
                e.CellElement.Text = GetLookupValue1(cell.Value);
            }
            else
            {
                e.CellElement.Text = GetLookupValue2(cell.Value);
            }
        }
    }

    I hope this helps. If you need further assistance, I will be glad to help.

    Regards,
    Jack
    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jens
    Jens avatar
    11 posts
    Member since:
    Apr 2008

    Posted 04 Jan 2010 Link to this post

    Hi,

    I have a similiar problem and thus post it in this thread.

    When editing a cell in my ComboCoxColumn, I want to restrict the offered items to a subset of the ComboBoxColumn's data source (depending on certain conditions).

    To do that, I changed the column's data source on the BeginEdit Event and changed it back to the complete data source on the EndEdit Event.

    That worked fine in Q2/2009.

    After updating to Q3 SP1/2009, it doesn't work that way, because now every row's display is refreshed when I start editing -- and that is AFTER I changed the data source. The result is, that most cell are blank now (because the edit data source has only very few entries) during editing. Once editing is finished, the complete data source is set to the column and all entries appear completely.

    So the question is: How do I prevent the not-edited cells' display text from being updated while the "wrong" data source is set?

    Thank you, Jens
  5. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 04 Jan 2010 Link to this post

    Hi Jens,

    In this case you should handle CellFormatting method and provide the cell value manually. I demonstrated this in my sample with two methods that you should create GetLookupValue1 and GetLookupValue2. I hope this helps.

    Best wishes,
    Jack
    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.
  6. v-govinr@microsoft.com
    v-govinr@microsoft.com avatar
    18 posts
    Member since:
    Jun 2010

    Posted 18 Jun 2010 Link to this post

    Hi,
    Please tell me the location of sample,I have to implement similar scenario
  7. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 23 Jun 2010 Link to this post

    Hello Govind Ramaswamy,

    Please look at my previous post in this forum thread. It contains the example I have concerned.

    Sincerely yours,

    Jack
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Arun
    Arun avatar
    14 posts
    Member since:
    Oct 2010

    Posted 11 Nov 2010 Link to this post

    i am not able to find the cellFormat event. can you please attach the complete solution ?
  9. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 11 Nov 2010 Link to this post

    Hello Arun,

    What version of the controls are you using?
    the cell formatting event is part of the RadGridView and handled as below:

    Private Sub RadGridView1_CellFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
        '// Handle cell formatting event here
    End Sub
    Hope that helps
    Richard
  10. Arun
    Arun avatar
    14 posts
    Member since:
    Oct 2010

    Posted 11 Nov 2010 Link to this post

    Is the same event available in the Silverlight version - 2010.2.924.1040 ?

    I need to perform the same operation of Changing the Combo box values based onthe selection in the first combo column. Can you Please give me a sample applcaition

    Arun



  11. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 11 Nov 2010 Link to this post

    Hi Arun,

    As far as I'm aware, the same event is not part of the Silverlight offering. If you have a question specific to the Silverlight suite of tools, please could you direct this question to the Silverlight forums.
    Thanks
    Richard
  12. Praveena
    Praveena avatar
    3 posts
    Member since:
    Feb 2011

    Posted 19 Feb 2011 Link to this post

    Hi,
     I am using combo boxes inside radgridview. I have 2 comboboxes. Once i change the value in first combo box, based on that the second combo box pops up. Binding of my 2nd combo box is working based on first combo. However when i go to second row, the first row's second combo box goes blank. If i click on that cell in first row, second row's same cell goes blank. Is there any solution for this problem.

    Regards,
    Praveena
  13. Svett
    Admin
    Svett avatar
    728 posts

    Posted 23 Feb 2011 Link to this post

    Hi Praveena,

    You can read the knowledge base article RadComboBoxEditor in GridViewComboBoxColumn dependant on the value of another cell. It describes in depth how you can accomplish this scenario. Could you share with us the code that implements your scenario? 

    Best wishes,
    Svett
    the Telerik team
  14. Praveena
    Praveena avatar
    3 posts
    Member since:
    Feb 2011

    Posted 23 Feb 2011 Link to this post

    Hi,

        I have resolved it just one hour ago. Richard helped me through another thread.

    Thnx
    Praveena
  15. Svett
    Admin
    Svett avatar
    728 posts

    Posted 25 Feb 2011 Link to this post

    Hi Praveena,

    I am glad to hear that.

    Please remember to mark the helpful reply as an answer.

    All the best,
    Svett
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  16. Mark
    Mark avatar
    18 posts
    Member since:
    Nov 2011

    Posted 10 Jan 2015 in reply to Svett Link to this post

    The link is broken....this is a very frustrating thread....wrong code up front, no links provided by previous Telerik support, finally you provide a link and it's broken.  I just want a simple example of how the contents of one dataset bound combobox changes based on a second combobox in the same radgridview row.  As Jens explained, the dataset used as the datasource for the combobox that I need filtered applies to all of the rows in the radgridview.  When I select the combo's drop down, it filters all the rows in the radgridview combo column and many turn blank.
  17. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 12 Jan 2015 Link to this post

    Hi Mark,

    Thank you for writing.

    Please find an updated address of our kb article: Cascading ComboBoxes in RadGridView.

    Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready