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

How to Bind one ComboBox in Grid with different item source.

10 Answers 584 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chetan
Top achievements
Rank 1
Chetan asked on 15 Nov 2010, 08:27 AM
Hello Telerik team,

I have one Grid there i am facing some problems. 

My problem are
 
1. i need to bind combo box in GridRow as per another column value / another selected combo box values. for example, if there are two combo boxes in Grid 1. Feature Name and 2. Discipline then as per selected Feature,  Discipline combo box should bind, if i selected "NEF" feature then only "PM" Should bind else  CS, AB and CD. I required this functionality while editing a row and adding new row on click to addnewitem button.

2. in Grid i need to show HTML editor on click of a button which is there in Grid Column.

Waiting for your reply.

Thanks
Csingh
 

10 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 15 Nov 2010, 10:04 AM
Hi Chetan,

Considering your first requirement, you may take a look at this blog post that covers the exact same scenario. As for defining a button in a column, you may run through this help article. Once you create the column, you can handle the Click event and execute the desired behavior.
 

Best wishes,
Maya
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
Chetan
Top achievements
Rank 1
answered on 15 Nov 2010, 01:13 PM
Hello Maya,

Its not working for me because i am using MVVM Design patterns and binding GridComboBox at runtime in ViewModel on grid load events. My Problems are

1. In grid there is 1 column status having 4 values A,B,C and D. on GridRowloading if status is A then in combobox only A and D will bind and if B then B and D, If C then Only C, If D then only D. *** while adding new record using "Click on add new item button" only Status A will be bind.

2. there is two columns feature & Discipline and Two different datasource for Discipline combobox. As per selected feature Discipline will bind with requested datasource.

Please check my code and let me know ASAP, how to make it possible.

in ViewModel :

public

 

void gridViewTaskPlanning_RowLoaded(object sender, RowLoadedEventArgs e)

 

{

 

if (e.Row is GridViewRow && !(e.Row is GridViewNewRow))

 

{

 

RadGridView _radGridView = e.GridViewDataControl as RadGridView;

 

 

Task _task = e.DataElement as Task;

 

 

switch (_task.StatusName)

 

{

 

case "A":

 

e.Row.Background =

new SolidColorBrush(InProgress);

 

 

break;

 

 

case "B":

 

e.Row.Background =

new SolidColorBrush(NotStarted);

 

 

break;

 

 

case "C":

 

e.Row.Background =

new SolidColorBrush(Postponed);

 

 

break;

 

 

case "D":

 

e.Row.Background =

new SolidColorBrush(Completed);

 

 

break;

 

 

default:

 

e.Row.Background =

new SolidColorBrush(NotStarted);

 

 

break;

 

}

(_radGridView.Columns[

"Feature Name"] as GridViewComboBoxColumn).ItemsSource = FeatureList;

 

(_radGridView.Columns[

"Discipline"] as GridViewComboBoxColumn).ItemsSource = DisciplineList;

 

(_radGridView.Columns[

"Status"] as GridViewComboBoxColumn).ItemsSource = StatusList;

 

}

}



In XAML :

<

 

telerik:GridViewComboBoxColumn

 

 

UniqueName="Feature Name"

 

 

SelectedValueMemberPath="FeatureID"

 

 

DisplayMemberPath="FeatureName" IsResizable="False"

 

 

DataMemberBinding="{Binding FeatureID,Mode=TwoWay}"

 

 

ItemTemplate="{StaticResource FeatureComboBoxCustomTemplate}"

 

 

Width="180"

 

 

IsReadOnlyBinding="{Binding Path=., Converter={StaticResource GridRowReadOnlyConvertor}}">

 

 

 

<telerik:GridViewComboBoxColumn.Header>

 

 

 

<StackPanel>

 

 

 

<TextBlock Text="Feature Name" VerticalAlignment="Center" TextWrapping="Wrap" />

 

 

 

<TextBlock Text="*" Foreground="Red" />

 

 

 

</StackPanel>

 

 

 

</telerik:GridViewComboBoxColumn.Header>

 

 

 

</telerik:GridViewComboBoxColumn>

 



<

 

telerik:GridViewComboBoxColumn

 

 

DataMemberBinding="{Binding DisciplineID,Mode=TwoWay}"

 

 

SelectedValueMemberPath="DisciplineId"

 

 

DisplayMemberPath="DisciplineAlias" IsResizable="False"

 

 

ItemTemplate="{StaticResource DisciplineComboBoxCustomTemplate}"

 

 

UniqueName="Discipline" Width="90"

 

 

IsReadOnlyBinding="{Binding Path=., Converter={StaticResource GridRowReadOnlyConvertor}}">

 

 

 

<telerik:GridViewComboBoxColumn.Header>

 

 

 

<StackPanel>

 

 

 

<TextBlock Text="Discipline" VerticalAlignment="Center" />

 

 

 

<TextBlock Text="*" Foreground="Red" />

 

 

 

</StackPanel>

 

 

 

</telerik:GridViewComboBoxColumn.Header>

 

 

 

</telerik:GridViewComboBoxColumn>

 



<

 

telerik:GridViewComboBoxColumn

 

 

DataMemberBinding="{Binding StatusID,Mode=TwoWay}"

 

 

SelectedValueMemberPath="StatusID"

 

 

DisplayMemberPath="StatusName"

 

 

UniqueName="Status" Width="80"

 

 

ItemTemplate="{StaticResource StatusComboBoxCustomTemplate}"

 

 

IsReadOnlyBinding="{Binding Path=., Converter={StaticResource GridStausColumnReadOnlyConvertor}}"

 

 

IsResizable="False"

 

 

>

 

 

 

<telerik:GridViewComboBoxColumn.Header>

 

 

 

<StackPanel>

 

 

 

<TextBlock Text="Status" VerticalAlignment="Center" TextWrapping="Wrap" />

 

 

 

<TextBlock Text="*" Foreground="Red" />

 

 

 

</StackPanel>

 

 

 

</telerik:GridViewComboBoxColumn.Header>

 

 

 

</telerik:GridViewComboBoxColumn>

 


in Xaml.cs

gridViewTaskPlanning.RowLoaded +=

new EventHandler<RowLoadedEventArgs>(taskPlanningViewModel.gridViewTaskPlanning_RowLoaded);

 



0
Chetan
Top achievements
Rank 1
answered on 16 Nov 2010, 08:06 AM
Hello Telerik Team,


Please check Above issues.(very urgent)

waiting for your reply.

Thanks
Csingh
0
Maya
Telerik team
answered on 17 Nov 2010, 11:17 AM
Hi Chetan,

1. You may introduce a property in your Business object holding the available values for a particular item. Once you set them, you need to define the ItemsSourceBinding property of the GridViewComboBoxColumn pointing to it. You may take a look at this forum thread for a reference and sample project on the topic.   
2. I believe the blog post stated above answers to your requirements.

Sincerely yours,
Maya
the Telerik team
See What's New in RadControls for Silverlight in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
0
Chetan
Top achievements
Rank 1
answered on 17 Nov 2010, 06:44 PM
hello maya,

u r not getting my point. i m not asking how to bind  List<string> Types  with combo box. i am able to bind GridViewComboBoxColumn with datasource, but my requirement is how to bind same GridViewComboBoxColumn with different itemsource as per rowwise. I mean if grid having 10 rows ,4 columns(one column is GridViewComboBoxColumn ) then for each row as per column1 values GridViewComboBoxColumn should bind with required itemsource. 

example

Emp id    EmpName    Department    SubDepartment
1            A                  Technical       Combobox should hasJAVA, C, C++, .NET etc
2.           B                   Account       combobox should has SALARY, BANK, TAX etc
3.           C                    HR               Combobox should has Tranining, Rcrmt, Apprsl etc


I hope this time its understable for you. If you have any doubt then feel free to revert back.


Thanks
Csingh
0
Maya
Telerik team
answered on 18 Nov 2010, 05:17 PM
Hello Chetan,

Following up the sample project of the mentioned forum thread, you need to extend it just a bit so that it fulfills the goal of having separate source for the ComboBox on the different rows.
I am sending you the sample project with the few improvements made.
 

All the best,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Chetan
Top achievements
Rank 1
answered on 18 Nov 2010, 07:17 PM
How to do same with MVVM?
0
Vlad
Telerik team
answered on 19 Nov 2010, 08:21 AM
Hello,

Can you clarify what is not in MVVM style in the attached project?

Greetings,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Chetan
Top achievements
Rank 1
answered on 23 Nov 2010, 06:37 PM
Hello Maya,

Still you are not able to understand my requirement. If you check your code then you will find you are not binding your combobox with different itemsource, you are binding combo box with same list and the list having different values.

for your help again i would like to explain my requirement.if you are not able to understand pls revert back.

example

Emp id    EmpName    Department    SubDepartment
1            A                  Technical       Combobox should hasJAVA, C, C++, .NET etcc (Different ItemSource, TechnicalEntityList)
2.           B                   Account       combobox should has SALARY, BANK, TAX etc(Different ItemSource, AccountEntityList)
3.           C                    HR               Combobox should has Tranining, Rcrmt, Apprsl etc(Different ItemSource, HREntityList)

TechnicalEntityList contain with following fields
1. DepartmentId
2. DepartmentName




Thanks
CSingh

0
4thEstate
Top achievements
Rank 1
answered on 15 Jun 2017, 06:49 PM

Too bad Telerik never could understand that you wanted to bind two SEPARATE data sources MVVM style (who uses code behind anyways, a coupled nightmare).....to a RadDataGrid.

Would be nice if Telerik's example code in documentation was not for "code behind" and instead focused more on MVVM real world examples. 

Tags
GridView
Asked by
Chetan
Top achievements
Rank 1
Answers by
Maya
Telerik team
Chetan
Top achievements
Rank 1
Vlad
Telerik team
4thEstate
Top achievements
Rank 1
Share this question
or