Search code examples
c#silverlightdata-bindingsilverlight-4.0domaindatasource

Insert an item into a DomainDataSource in a specific position/index


In my silverlight4/C# application, I have a comboBox which is bound to a DomainDataSource.

I'm adding some items in the runtime to that DomainDataSource to be shown in the comboBox, but I want to add some items in the beginning or in a specific index, not in the end.

Is there a chance to achieve that?

Thanks,


Solution

  • You can add a sort description to the DomainDataSource, so if you're inserting things which have a particular field value that means they're in the middle rather than the end then yes ... you can add items at specific places.

    e.g.

    <riaControls:DomainDataSource x:Name="source" QueryName="GetProducts" AutoLoad="true">
            <riaControls:DomainDataSource.DomainContext>
                <domain:ProductDomainContext />
            </riaControls:DomainDataSource.DomainContext>   
            <riaControls:DomainDataSource.SortDescriptors>
                <riaData:SortDescriptor PropertyPath="ProductID" Direction="Ascending" />
            </riaControls:DomainDataSource.SortDescriptors>
        </riaControls:DomainDataSource>