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

Cascading ComboBoxes in RadGridView

15 Answers 449 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 04 Nov 2009, 01:12 AM
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.

15 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 06 Nov 2009, 08:28 AM
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.
0
Jens
Top achievements
Rank 1
answered on 04 Jan 2010, 11:04 AM
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
0
Jack
Telerik team
answered on 04 Jan 2010, 12:20 PM
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.
0
v-govinr@microsoft.com
Top achievements
Rank 1
answered on 18 Jun 2010, 07:53 AM
Hi,
Please tell me the location of sample,I have to implement similar scenario
0
Jack
Telerik team
answered on 23 Jun 2010, 07:19 PM
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
0
Arun
Top achievements
Rank 1
answered on 11 Nov 2010, 10:18 AM
i am not able to find the cellFormat event. can you please attach the complete solution ?
0
Richard Slade
Top achievements
Rank 2
answered on 11 Nov 2010, 10:27 AM
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
0
Arun
Top achievements
Rank 1
answered on 11 Nov 2010, 10:37 AM
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



0
Richard Slade
Top achievements
Rank 2
answered on 11 Nov 2010, 10:53 AM
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
0
Praveena
Top achievements
Rank 1
answered on 19 Feb 2011, 08:28 AM
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
0
Svett
Telerik team
answered on 23 Feb 2011, 08:02 AM
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
0
Praveena
Top achievements
Rank 1
answered on 23 Feb 2011, 08:06 AM
Hi,

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

Thnx
Praveena
0
Svett
Telerik team
answered on 25 Feb 2011, 02:19 PM
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!
0
Mark
Top achievements
Rank 2
answered on 10 Jan 2015, 09:32 PM
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.
0
Hristo
Telerik team
answered on 12 Jan 2015, 01:55 PM
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.

 
Tags
GridView
Asked by
Nick
Top achievements
Rank 1
Answers by
Jack
Telerik team
Jens
Top achievements
Rank 1
v-govinr@microsoft.com
Top achievements
Rank 1
Arun
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Praveena
Top achievements
Rank 1
Svett
Telerik team
Mark
Top achievements
Rank 2
Hristo
Telerik team
Share this question
or