ComboBox column is emty in GridView bound to domaindatasource

7 posts, 1 answers
  1. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 10 Apr 2011 Link to this post

    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?


  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 11 Apr 2011 Link to this post

    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
  3. DevCraft banner
  4. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 11 Apr 2011 Link to this post

    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.

  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 11 Apr 2011 Link to this post

    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
  6. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 11 Apr 2011 Link to this post

    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?


  7. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 11 Apr 2011 Link to this post

    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
  8. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 11 Apr 2011 Link to this post

    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. 
Back to Top
DevCraft banner