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

Relational RadCombobox (Country-City , Make-Model)

5 Answers 148 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bülent Yalman
Top achievements
Rank 1
Bülent Yalman asked on 31 Jan 2012, 12:33 AM

            I have an application (I’m using Silverlight,Prism,mvvm,wcf ria services,entity data model).
In my Customer entity i have two properties CountryID and CityID related Country and City Entities.
 I get Countries with Cities by include fromCustomerDomainService.
 I try configure in my gridview relation with Country and City radcomboboxes.
In detailview (in another view which is comboboxes are not in gridview) i can bind the City radcombobox itemsource to Country RadCombobox SelectedItem.Cities (ItemsSource="{Binding SelectedItem.Cities, ElementName=CountryRadCombobox}"). But in gridview i can't access the Country radcombobox.Because it is in data template. How can i solve this problem.Thank you for your help.. 



5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 31 Jan 2012, 08:35 AM
Hi,

 You may review this blog post. There is an implementation of a common scenario when entering data is a cascade of combo boxes. The list in the next combo is populated after selecting a value in the previous - its ItemsSource depend on the SelectedItem of the second ComboBox.

Does this fits to your scenario?

Greetings,
Didie
the Telerik team

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

0
Bülent Yalman
Top achievements
Rank 1
answered on 31 Jan 2012, 02:02 PM
Hi again.. your posted solution didn't work to me.Because it makes some business logic difficulty such as crud operations etc. So after thinking how can i solve this problem i found a simple(may be funny :)) solution. In datatemplate of my gridviews giridviewdatacolumn i put the comboboxes inside a stackpanel. Now i can access the parent comboboxes SelectedItem with its name like this <ItemsSource="{Binding SelectedItem.Cities, ElementName=CountryCombobox}">. This cames with some sorting and filtering problem because there is now one column header  ("Country-City")  :).
But i think i can solve this with custom filtering and sorting. 
May be it is usefull for someone else looking for solution like this.
0
Bülent Yalman
Top achievements
Rank 1
answered on 31 Jan 2012, 06:57 PM
There is one more bug in my solution.Don't worry i solved that either :) When you use the solution above you will notice that when adding new row to the collection all cities unbound(picture before.png). The solution is seperate the DataTemplate GridViewDataColumn.CellTemplate and GridViewDataColumn.CellEditTemplate.Then in the GridViewDataColumn.CellTemplate change the itemsource binding city combobox to <ItemsSource="{Binding SelectedItem.Cities, ElementName=CountryCombobox,Mode=OneTime}"> thats it. The new 
 result seem like picture after.png :)  I hope this helps. Here is code for RadGridView...
 ( 
<telerik:RadGridView x:Name="RadGridViewCustomer"
             
            IsFilteringAllowed="True"
            ItemsSource="{Binding CustomersList, Mode=TwoWay}"
            AutoGenerateColumns="False" Margin="10,35,10,5"
            CanUserInsertRows="False"
            CanUserDeleteRows="False"
            AlternationCount="2"
            SelectedItem="{Binding SelectedCustomer, Mode=TwoWay}" 
            RowDetailsVisibilityMode="VisibleWhenSelected" >
       
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn 
                    DataMemberBinding="{Binding ID}"
                    Header="ID" >
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding ID}"/>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>


                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn 
                    DataMemberBinding="{Binding Name}"
                    Header="Name" IsFilterable="True">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}"/>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn
                    DataMemberBinding="{Binding Surname}"
                    IsFilterable="True"
                    Header="Surname">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Surname}" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Surname, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn 
                    DataMemberBinding="{Binding Phone}"
                    IsFilterable="True"
                    Header="Phone">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Phone}" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Phone, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn 
                    DataMemberBinding="{Binding BirthDate}"
                    IsFilterable="True"
                    Header="BirthDate">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding BirthDate, StringFormat=\{0:d\}}" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate>
                            <telerik:RadDatePicker SelectedValue="{Binding BirthDate, Mode=TwoWay, StringFormat=\{0:d\}, UpdateSourceTrigger=PropertyChanged}" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn 
                    
                    Header="Country - City">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <telerik:RadComboBox
                                  MinWidth="80"
                       x:Name="CountryCombobox"
    Style="{StaticResource RadComboBoxStyle1}"
    IsFilteringEnabled="True" 
   
    CanAutocompleteSelectItems="True"
    IsEditable="False" 
    EmptyText="Choose Country.."
                     Background="Transparent"
    ClearSelectionButtonVisibility="Visible"
    ClearSelectionButtonContent="Clear Selection.."
    SelectedValue ="{Binding CountryID, Mode=TwoWay}"
    ItemsSource="{Binding Country.CountriesList, Source={StaticResource Locator},UpdateSourceTrigger=PropertyChanged}"
    DisplayMemberPath="CountryName" 
                        SelectedValuePath="ID" 
                        
                            />
                                <telerik:RadComboBox
                       MinWidth="80"
    Style="{StaticResource RadComboBoxStyle1}"
    IsFilteringEnabled="True" 
   
    CanAutocompleteSelectItems="True"
    IsEditable="False" 
    EmptyText="Choose City.."
                     Background="Transparent"
  
    SelectedValue ="{Binding CityID, Mode=TwoWay}"
    ItemsSource="{Binding SelectedItem.Cities, ElementName=CountryCombobox,Mode=OneTime}"
    DisplayMemberPath="CityName" 
                        SelectedValuePath="ID" 
                                />
                            </StackPanel>


                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <telerik:RadComboBox
                                    MinWidth="80"
                       x:Name="CountryEditCombobox"
   
    IsFilteringEnabled="True" 
   
    CanAutocompleteSelectItems="True"
    IsEditable="False" 
    EmptyText="Choose Country.."
                        Background="Transparent"
    ClearSelectionButtonVisibility="Visible"
    ClearSelectionButtonContent="Clear Country.."
    SelectedValue ="{Binding CountryID, Mode=TwoWay}"
    ItemsSource="{Binding Country.CountriesList, Source={StaticResource Locator}}"
    DisplayMemberPath="CountryName" 
                        SelectedValuePath="ID" 
                        
                            />
                                <telerik:RadComboBox
                       
    MinWidth="80"
    IsFilteringEnabled="True" 
    Margin="5,0,0,0"
    CanAutocompleteSelectItems="True"
    IsEditable="False" 
    EmptyText="Choose City.."
                     Background="Transparent"
      ClearSelectionButtonVisibility="Visible"
    ClearSelectionButtonContent="Clear City.."
    SelectedValue ="{Binding CityID, Mode=TwoWay}"
    ItemsSource="{Binding SelectedItem.Cities, ElementName=CountryEditCombobox}"
    DisplayMemberPath="CityName" 
                        SelectedValuePath="ID" 
                                />
                            </StackPanel>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
 ) 
0
Houdini
Top achievements
Rank 1
answered on 02 Feb 2012, 08:41 PM
My situation is almost like this but not quiet there. I am binding my radGridView to a radDomainDataSource, which is pulling from my DomainService class and getting the records of all "Acquisition Status" that comes from the AcquisitionStatus table (via LINQtoSQL model). The AcquisitionStatus has a field called AcquistionTypeID (foreign Key), which points to the AcquisitionType table. All works well until I tried adding a GridViewComboBoxColumn to the radGridView to display the "Types of Acquisition" (a field in my AcquisitionType table) as opposed to displaying the AcquisitionTypeID field. All in all, I want to see the Types (Compulsory, private, etc...) in the box as oppose to seeing 1,2,3...etc.
0
Dimitrina
Telerik team
answered on 03 Feb 2012, 03:16 PM
Hello,

 As I have understood you, your records are of type "AcquisitionStatus" and each record has a field AcquistionTypeID. Then you want the GridViewComboBoxColumn to show the  AcquisitionTypes based on the  AcquistionTypeID for the record. If this is the case then please try using ItemsSourceBinding instead of ItemsSource for binding the combobox column.


Kind regards,
Didie
the Telerik team

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

Tags
GridView
Asked by
Bülent Yalman
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Bülent Yalman
Top achievements
Rank 1
Houdini
Top achievements
Rank 1
Share this question
or