Search code examples
silverlightdata-bindingsilverlight-4.0comboboxwcf-ria-services

Silverlight childwindow combobox lookup


I am trying my hardest with silverlight but keep getting caught at hurdles for simple tasks. I have a main datagrid on my main form that lists addresses. I then have a child window that allows a user to edit these addresses with a combobox that does a country look up. I have an AdreessDomainDataSource and a CountryDomainDataSource. I have my combo box in my child window with code as follows:

         <riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my:Country, CreateList=true}" Height="0" Name="CountryDomainDataSource" QueryName="GetCountriesQuery" Width="0">
        <riaControls:DomainDataSource.DomainContext>
            <my:CountriesContext />
        </riaControls:DomainDataSource.DomainContext>
    </riaControls:DomainDataSource>


    <riaControls:DomainDataSource AutoLoad="False" d:DesignData="{d:DesignInstance my:Address, CreateList=true}" Height="0" Name="AddressDomainDataSource" QueryName="GetAddressQuery" Width="0" LoadDelay="10000">
        <riaControls:DomainDataSource.DomainContext>
            <my:AddressContext />
        </riaControls:DomainDataSource.DomainContext>
        <riaControls:DomainDataSource.QueryParameters>
            <riaControls:Parameter ParameterName="intAddressID" />
        </riaControls:DomainDataSource.QueryParameters>
    </riaControls:DomainDataSource>



    <Grid DataContext="{Binding ElementName=AddressDomainDataSource, Path=Data}" HorizontalAlignment="Left" Margin="63,27,0,0" Name="Grid1" VerticalAlignment="Top">

This writes back correctly when i change to a different item in the list but on start up it is always replaced to the first item in the CountryDomainDataSource list. I have put a breakpoint on my web.g.vb code and it appears that intCountryID is set correctly on start up but straight after returning it, it is getting overwritten by the first value in the list. I have not written any code to set this value to the first value in my CountryDomainDataSource list? It appears that after the CountryDomainDataSource_LoadedData event is finished then it sets the countryid there. Is there anyway to make my CountryDomainDatasource load first and then my AddressDomainDatasource second or am i doing something silly or wrong here as i have been scratching my head over this for awhile?

Any help would be much appreciated.

Thanks


Solution

  • When a DDS loads data successfully, it will select the first item in the list. For this reason (among others), I recommend you don't use it to populate ComboBoxes. Here are a couple posts put together by Jeff and me explaining the reasoning and better alternatives.