I am trying to bind the data to ComboBox using WCF RIA. Only for data binding is fine but on the same time I want to be already selected for the specified item after binding. For this case, I don't know how can I do to achieve this. May be the way that my data binding also wrong.
Here is my Entity
public class Customer
{
[System.ComponentModel.DataAnnotations.Key()]
public int CustomerId { get; set; }
public string CustomerName { get; set; }
}
Here is WCF RIA Service
public class CustomerDomainService : DomainService
{
public IEnumerable<Customer> GetCustomers()
{
List<Customer> rtnList = new List<Customer>();
DataTable dt = (new CustomerBLL()).GetAllCustomers;
foreach (DataRow dr in dt.Rows) {
rtnList.Add(new Customer {
CustomerId = Convert.ToInt32(dr("CustomerID")),
CustomerName = Convert.ToString(dr("CustomerName"))
});
}
return rtnList;
}
}
Here is XAML
<ComboBox Name="CustomerComboBox" HorizontalAlignment="Left" Height="25" Width="150" Grid.Column="1" Grid.Row="1" ItemsSource="{Binding ElementName=CustomerDomainDataSource, Path=Data}" DisplayMemberPath="CustomerName" SelectedValuePath="CustomerId"/>
<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my1:Customer, CreateList=true}" Height="0" Name="CustomerDomainDataSource" QueryName="GetCustomersQuery" Width="0">
<riaControls:DomainDataSource.DomainContext>
<my:CustomerDomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
Regards
I recommend you start with these two posts.
There's a sample that shows a number of different configurations as well as code snippets and explanation to get you started.