sorry change to
var carrierList = from c in db.CARRIERs
select c;
I would appreciate any help with databinding a ComboBox in WPF and with any other suggestions you might have about how Ive gone about this app. (Thanks in advance!)
1. A master-detail WPF application uses four tables: EMPLOYEE (the Master), DEPEND (Dependent, the Detail), CARRIER and GROUP (lookups). A ComboBox is bound in XAML to CARRIER (two fields: CARRCODE and CARRIER_NA (Name) via ItemsSource but fails to databind (see screenshot in the attached doc):
<GridViewColumn Header="Carrier" Width="100">
<GridViewColumn.CellTempla
<DataTemplate>
<ComboBox
SelectedValuePath="CARRCOD
SelectedValue="{Binding Path=CARRCODE}"
Margin="-6,0,-6,0" Width="Auto"
x:Name="cboCarrier"
IsSynchronizedWithCurrentI
ItemsSource="{Binding Source={StaticResource CarrierView}}">
<ItemsControl.ItemTemplate
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<TextBlock Name="Carrier"
Text="{Binding Path=CARRIER_NA}" />
<TextBlock Width="5"> ( </TextBlock>
<TextBlock Name="Code"
Text="{Binding Path=CARRCODE}" />
<TextBlock Width="5">)</TextBlock>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplat
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTempl
</GridViewColumn>
2. StaticResource CarrierView is set in App.xaml with other CollectionViewSources as follows:
<Application.Resources>
<CollectionViewSource x:Key="MasterView" />
<CollectionViewSource Source="{Binding Source={StaticResource MasterView}, Path='DEPENDs'}" x:Key="DetailView" />
<CollectionViewSource x:Key="GroupView" />
<CollectionViewSource x:Key="CarrierView" />
</Application.Resources>
3. Here is the code-behind:
public partial class Window1 : Window
{
private Billing03DataContext db = new Billing03DataContext();
private IEnumerable<EMPLOYEE> EEData;
private CollectionViewSource MasterViewSource;
private CollectionViewSource DetailViewSource;
private CollectionViewSource CarrierViewSource;
private CollectionViewSource GroupViewSource;
private BindingListCollectionView MasterView;
private BindingListCollectionView DetailView;
private BindingListCollectionView CarrierView;
private BindingListCollectionView GroupView;
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.EEData = db.EMPLOYEEs;
var carrierList = from c in db.CARRIERs
select c.CARRIER_NA;
var groupList = from g in db.GROUPs
select g.GROUPNAME;
this.MasterViewSource = (CollectionViewSource)this
this.DetailViewSource = (CollectionViewSource)this
this.CarrierViewSource = (CollectionViewSource)this
this.GroupViewSource = (CollectionViewSource)this
MasterViewSource.Source = this.EEData;
CarrierViewSource.Source = carrierList;
GroupViewSource.Source = groupList;
this.MasterView = (BindingListCollectionView
this.MasterView.CurrentCha
this.DetailView = (BindingListCollectionView
this.CarrierView = (BindingListCollectionView
this.GroupView = (BindingListCollectionView
}
void MasterView_CurrentChanged(
{
this.DetailView = (BindingListCollectionView
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks! This also works but I'm not sure why:
var carrierList = from c in db.CARRIERs
select new { c.CARRIER_NA };
The "new" instantiates an anonymous type, right -- but why doesn't just a plain SELECT work? Is this overkill if I only want the carrier name, i.e. DisplayMemberPath="CARRIER
Business Accounts
Answer for Membership
by: gauthampjPosted on 2009-01-30 at 00:22:29ID: 23506126
here
var carrierList = from c in db.CARRIERs
select c.CARRIER_NA;
u are only selecting c.CARRIER_NA field but u have done binding for both CARRIER_NA and CARRCODE
<StackPanel Orientation="Horizontal" >
<TextBlock Name="Carrier"
Text="{Binding Path=CARRIER_NA}" />
<TextBlock Width="5"> ( </TextBlock>
<TextBlock Name="Code"
Text="{Binding Path=CARRCODE}" />
<TextBlock Width="5">)</TextBlock>
</StackPanel>
in the anonymous type only CARRIER_NA will be there.try changing to
var carrierList = from c in db.CARRIERs
select c.CARRIER_NA,c.CARRCODE;