[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

WPF ComboBox DataBinding

Asked by dma111 in WPF and Silverlight

Tags: WPF, XAML, C#, DataBinding, ComboBox, Visual Studio, Expression Blend

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.CellTemplate>
        <DataTemplate>
            <ComboBox
                  SelectedValuePath="CARRCODE" IsEditable="False"
                  SelectedValue="{Binding Path=CARRCODE}"  
                  Margin="-6,0,-6,0" Width="Auto"
                  x:Name="cboCarrier"
                  IsSynchronizedWithCurrentItem="False"      
                  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.ItemTemplate>
            </ComboBox>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</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.FindResource("MasterView");
        this.DetailViewSource = (CollectionViewSource)this.FindResource("DetailView");
        this.CarrierViewSource = (CollectionViewSource)this.FindResource("CarrierView");
        this.GroupViewSource = (CollectionViewSource)this.FindResource("GroupView");
       
        MasterViewSource.Source = this.EEData;
        CarrierViewSource.Source = carrierList;
        GroupViewSource.Source = groupList;

        this.MasterView = (BindingListCollectionView)this.MasterViewSource.View;
        this.MasterView.CurrentChanged += new EventHandler(MasterView_CurrentChanged);
        this.DetailView = (BindingListCollectionView)this.DetailViewSource.View;
        this.CarrierView = (BindingListCollectionView)this.CarrierViewSource.View;
        this.GroupView = (BindingListCollectionView)this.GroupViewSource.View;
    }

    void MasterView_CurrentChanged(object sender, EventArgs e)
    {
        this.DetailView = (BindingListCollectionView)this.DetailViewSource.View;
    }

 


Attachments:
 
ComboBox doesn't DataBind -- screenshot included.
 
[+][-]01/30/09 12:22 AM, ID: 23506126Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: WPF and Silverlight
Tags: WPF, XAML, C#, DataBinding, ComboBox, Visual Studio, Expression Blend
Sign Up Now!
Solution Provided By: gauthampj
Participating Experts: 1
Solution Grade: A
 
[+][-]01/30/09 12:25 AM, ID: 23506141Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]01/30/09 09:28 AM, ID: 23510661Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625