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

ComboBox column is emty in GridView bound to domaindatasource

6 Answers 64 Views
DomainDataSource
This is a migrated thread and some comments may be shown as answers.
HDC
Top achievements
Rank 1
HDC asked on 10 Apr 2011, 02:44 PM
I have a DataViewGrid bound to a raddomaindatasource

I have a ComboBoxColumn in the dataviewgrid, the combobox is bound to a different raddomaindatasource

When i run the code, the combobox column is empty, but when i click the combobox column on any row , all the values for the comboboxcolumn are filled in on all rows.

Here is the XAML:

<Grid x:Name="LayoutRoot">
      
    <telerik:RadDomainDataSource AutoLoad="True" Height="0" Width="0"                                      
                                  x:Name="organizationDomainDataSource" 
                                  QueryName="GetOrganizationsQuery">
        <telerik:RadDomainDataSource.DomainContext>
            <my1:ExqiOfficeDomainContext />
        </telerik:RadDomainDataSource.DomainContext>
    </telerik:RadDomainDataSource>
    <telerik:RadDomainDataSource AutoLoad="True" Height="0" Width="0"                                      
                                  x:Name="countriesDomainDataSource" 
                                  QueryName="GetCountriesQuery">
        <telerik:RadDomainDataSource.DomainContext>
            <my1:ExqiOfficeDomainContext />
        </telerik:RadDomainDataSource.DomainContext>
    </telerik:RadDomainDataSource>
    <telerik:RadBusyIndicator 
        IsBusy="{Binding IsBusy, ElementName=OrganizationsGrid}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="300"></RowDefinition>
                <!--<RowDefinition Height="50"></RowDefinition> -->
                <RowDefinition Height="400"></RowDefinition>
            </Grid.RowDefinitions>
            <telerik:RadGridView x:Name="OrganizationsGrid" 
                                 ItemsSource="{Binding ElementName=organizationDomainDataSource, Path=DataView}"                                       
                                 AutoGenerateColumns="False" 
                                 IsReadOnly="True"
                                 IsBusy="{Binding IsBusy, ElementName=organizationDomainDataSource}" 
                                 Grid.Row="0"
                                 >                                    
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Header="Name" UniqueName="Name" Width="200"></telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="Address" UniqueName="Address" Width="150"></telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="Zip Code" UniqueName="Zipcode"></telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="Place" UniqueName="Place" Width="150"></telerik:GridViewDataColumn>
                    <telerik:GridViewComboBoxColumn Header="Country" UniqueName="CountryId" 
                                                    ItemsSource="{Binding ElementName=countriesDomainDataSource, Path=DataView}"
                                                    SelectedValueMemberPath="CountryId" 
                                                    DisplayMemberPath="Name">                        
                    </telerik:GridViewComboBoxColumn>
                    <telerik:GridViewDataColumn Header="VAT" UniqueName="VAT" Width="150"></telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="Created On" UniqueName="DateCreated"></telerik:GridViewDataColumn>
                </telerik:RadGridView.Columns>                
            </telerik:RadGridView>
              
        </Grid>
    </telerik:RadBusyIndicator>        
</Grid>

Did i miss something?


6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 11 Apr 2011, 07:14 AM
Hello peter,

You may take a look at this article for a reference.
 

Greetings,
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
HDC
Top achievements
Rank 1
answered on 11 Apr 2011, 07:29 AM
Thanks for your reply Maya,

I do understand how it works. There is maybe a bug here in the way it work when you use the raddomaindatasources to bind a grid column to a combo.

When you execute the code, you'll see the country column is empty for all records... but when you click any cell in the country column, correct values will be displayed in all of the rows. So it looks like the binding is not working correctly when the grid is first displayed and clicking in the column triggers an update of the entire column.

0
Maya
Telerik team
answered on 11 Apr 2011, 08:08 AM
Hello peter,

Generally, this behavior is not a bug, but more of an expected one. It would be present even if you are not using domain data source. The basic reason is that the data context of the GridViewComboBoxColumn is not the one of the row. Consequently, unless defined explicitly by StaticResource or in the code-behind, the column will not be able to find its corresponding source until being clicked and getting focus.
 

Regards,
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
HDC
Top achievements
Rank 1
answered on 11 Apr 2011, 10:30 AM
Hi Maya,

So what is the solution to this problem? Should i change the query that is running behind the data, so that i have a column returned with the name of the country?


0
Accepted
Maya
Telerik team
answered on 11 Apr 2011, 12:14 PM
Hello peter,

You may either define the Source property of the binding of the ItemsSource:

<UserControl.Resources>
    <telerik:RadDomainDataSourcex:Name="customersDataSource"
                                 AutoLoad="True"
                                 QueryName="GetCustomers">
        <telerik:RadDomainDataSource.DomainContext>
            <local:CustomersDomainContext/>
        </telerik:RadDomainDataSource.DomainContext>
    </telerik:RadDomainDataSource>
</UserControl.Resources>
  
<telerik:RadGridViewx:Name="grid">
            <telerik:RadGridView.Columns>                
                <telerik:GridViewComboBoxColumnDataMemberBinding="{Binding CustomerID}"
                                                UniqueName="Customer"         
                                                ItemsSource="{Binding DataView, Source={StaticResource customersDataSource}}"
                                                DisplayMemberPath="ContactName"
                                                SelectedValueMemberPath="CustomerID"/>            
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

or set the ItemsSource of the GridViewComboBoxColumn in the code-behind:
((GridViewComboBoxColumn)this.grid.Columns[2]).ItemsSource = customersContext.Load(customersContext.GetCustomersQuery()).Entities;

 

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
HDC
Top achievements
Rank 1
answered on 11 Apr 2011, 03:37 PM
Thanks a lot Maya,

Declaring the countries raddomaindatasource as a resource to the page and then setting it as static resource in the binding of the combobox did solve the problem.

I find this to be one of these hardest thing to comprehent in Silverlight. 
Tags
DomainDataSource
Asked by
HDC
Top achievements
Rank 1
Answers by
Maya
Telerik team
HDC
Top achievements
Rank 1
Share this question
or