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

GridViewComboBoxColumn & Different items source for each combo

13 Answers 335 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Richard Grimmer
Top achievements
Rank 1
Richard Grimmer asked on 25 Jan 2010, 03:16 PM
Not sure if this is possible in the current release - I'm able to set the items source of a combobox column in the codebehind (though apparently not in the XAML - AG_PARSER_ERROR), using :

((

 

GridViewComboBoxColumn)this.MyGrid.Columns[2]).ItemsSource = gd.MyItems[0].Rates[0].RateNames;

 


However, the complication arises since for each combo in the list, I'd need a different set of items....The data structure I'm using is similar to;

DataObj
    1. Name
    2. Id
    3. RatesList
        1.RateName
        2. RateValue

etc etc...., where the ItemsSource for the grid is set to a List<DataObj>

Anyone with ANY ideas!?!?!

13 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 25 Jan 2010, 03:20 PM
Hello Richard Grimmer,

For scenarios where Comboboxes  have different items sources for each row , the ItemsSourceBinding property of the ComboBoxColumn may be helpful .

You may see an example of using the ItemsSourceBinding in similar scenario at this help article

Best wishes,
Pavel Pavlov
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
Richard Grimmer
Top achievements
Rank 1
answered on 25 Jan 2010, 03:25 PM
Thanks for the speedy reply.

OK - I don't think that I was clear enough - I'm onboard with having to use a different ItemsSource for each row of the grid, but how would I go about coding that up - I can't seem to do it in pure XAML, and at the RowLoaded point, there appears to be no way to access the combo directly to set up the items source!?!?!
0
Pavel Pavlov
Telerik team
answered on 25 Jan 2010, 03:28 PM
Hi Richard ,

Can you please give me some details on your scenario (e.g.  what kind of data is going to be shown )  and  I will try to prepare a small sample project  to resemble it.

Kind regards,
Pavel Pavlov
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
Richard Grimmer
Top achievements
Rank 1
answered on 25 Jan 2010, 03:41 PM
OK - Here goes!

We have a dialog with a combo box. This combo box lists types of Tax Return. For each type of tax return, there are different Roles involved. When we select from the combo, the Grid needs to show the defined Roles for the selected type. Different types will have different roles. To do this, I'm tapping into SelectionChanged event on the combo, getting some data (in the format shown previously) and setting the grid's ItemsSource to the returned list of roles, with a column the showing Role Name. This part is fine - in the XAML we're setting the Grid's ItemsSource="{Binding}" and the Column's DataMemberBinding = "{Binding RoleName}". In the codebehind we're setting the Grid's DataContext = our returned list (embedded in another object since we also return information about the selected Return Type at this point) using Grid.DataContext=Dataobj.RolesList.

The next thing is that in the next column, we need to see a list of people - but only those that are appropriate for the Role specified. I.e. in row 1 of the grid, we'd need to see "Preparer" in col[0] and (for example) Person1 and Person2 in the combo, but for the next row, we'd need to see "Authoriser" in col[0], and Person3 and Person4 in the combo.

We get our data back as a list of Roles, each with a RoleID / Name and a List of People embedded inside the object. This could be changed however if a simpler / better method is available.

Many thanks.

0
Pavel Pavlov
Telerik team
answered on 27 Jan 2010, 05:35 PM
Hello Richard Grimmer,

Since this is a frequently requested behavior I have posted an online sample on how to achieve cascading combo selection with RadGridView. I believe the approach demonstrated there will be applicable to your scenario.

Best wishes,
Pavel Pavlov
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
varsha Motwani
Top achievements
Rank 1
answered on 17 Jun 2010, 08:39 AM
Hi,
I have to implement similar scenario.
I am not able to acess the link mentioned below
0
Vlad
Telerik team
answered on 17 Jun 2010, 08:45 AM
Hello,

 Here is the correct link:
http://blogs.telerik.com/pavelpavlov/posts/10-01-27/cascading_comboboxes_selection_in_radgridview_for_silverlight_and_wpf.aspx

Kind regards,
Vlad
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
Matthew
Top achievements
Rank 1
answered on 28 Oct 2011, 08:30 PM
Hi Vlad,

I tried this, but did not get the desired result...

I have 2 GridViewComboBoxColumns in my radGrid.  The First one is Product Line, the Second is Sub Product Line.

The Grid is initially populated with some data from a Database and each Row that is loaded has the SPL ItemsSource set to the available options for the PL.

At least that was the hope - it is still using the same bindings for every ComboBox in the whole column instead of for each Row.
0
Matthew
Top achievements
Rank 1
answered on 03 Nov 2011, 05:07 PM
Any thoughts on this...?
0
Pavel Pavlov
Telerik team
answered on 08 Nov 2011, 04:45 PM
Hello Matthew,

Since the example in the blog  does not exhibit the erroneous behavior , i must ask you to check what may be the difference between your implementation and mine.

Kind regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Matthew
Top achievements
Rank 1
answered on 10 Nov 2011, 01:05 AM
Hi Pavel,

In my project, there are actually 4 ComboBoxColumns that need to be setup in a cascading manner.

(1) Product Line --> (2) Sub Product Line --> (3) SLA --> (4) Obligation

Currently, I am setting the ItemsSource for Column (1) to a List of objects via a WCF Service call during the Page Load method.

Then a button is clicked, which populates the data into the Grid from a WCF Service Call.  In the "Completed" event of this WCF Call, I am looping through each record in the grid and setting the ItemsSource for Column (2) to another List of objects from WCF.  I would think that this is where it is going wrong, but I am not sure how to set the ItemsSource for the single Cell instead of the Column?

Column (1) seems to display the information correctly, such as:

Adjustment
Adjustment
Credit
Adjustment

However, Column (2) shows blank for each row, where it should show:

Override
Refund
Return
Override

Clicking the ComboBox for rows 1,2, and 4 all show the correct options - however the 3rd row shows the same options as the other rows (it should show a different set of items to choose from as shown below).

The "Adjustment" Product Line has 2 possible Sub Product Line options: Override, and Refund
The "Credit" Product Line has 2 possible Sub Product Line options: Return, and Cancel
0
Pavel Pavlov
Telerik team
answered on 10 Nov 2011, 02:44 PM
Hello Matthew,

Indeed GridViewComboBox column does not allow different sources per row when the ItemsSource property is used.  ItemsSource is common for all the rows.

For scenarios like yours, we have provided the ItemsSourceBinding property instead. It allows you to bind to a collection inside your business object. Since there is different instance n each row, the collection can be different too.

In other words, applied to your scenario, this would look like :

1. Add a collection property SubProductLines to your ProductLine class.
2. Use ItemsSourceBinding = {Binding SubProductLines} for the second combo column. ( instead of setting the ItemsSource property).

This should do the trick.

Best wishes,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Matthew
Top achievements
Rank 1
answered on 10 Nov 2011, 07:31 PM
Hey Pavel, thanks for your continued assistance.

I have added collection Properties to my Class and used ItemsSourceBinding for the GridViewComboBoxColumn.

<telerik:GridViewComboBoxColumn UniqueName="SubProductLine" Header="Sub Product Line" DataMemberBinding="{Binding SubProductLine, Mode=TwoWay, ValidatesOnExceptions=True}" ItemsSourceBinding="{Binding AvailableSubProductLines}"  SelectedValueMemberPath="Number" DisplayMemberPath="Description" />

This seems to be providing each record int he grid with a separate list of available options as you had suggested.

However, the GridViewComboBoxColumn for the Sub Product Line shows up as blank.  If I click on it, the correct items are listed and I can change it - but once the field loses focus it goes back to displaying blank...?

-------------
-- EDIT --
-------------

I got this to work properly.  I was setting the property value incorrectly to the SelectedValue, where I needed to Cast it as the Object type and use the "Number" property.

Row.SubProductLine = ((SubProductLine)ComboBox.SelectedItem).Number;


Thanks Pavel!
Tags
GridView
Asked by
Richard Grimmer
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Richard Grimmer
Top achievements
Rank 1
varsha Motwani
Top achievements
Rank 1
Vlad
Telerik team
Matthew
Top achievements
Rank 1
Share this question
or