0
votes

I'm trying to bind data to a combo box. The data is names from a table from database. Getting the data from the database works fine as I have tried to bind it to a List View and it displays fine. My problem is binding it to a combo box, it doesn't show anything.

Can anyone see where I have went wrong?

My code is the following...

   public string FullName
    {
        get
        {
            return String.Format("{0} {1}", _customer.ContactFirstName, _customer.ContactLastName);
        }
    }

and the XAML is

    <ComboBox x:Name="comboBox" Grid.Row="1" Grid.ColumnSpan="2" Height="20" ItemsSource="{Binding Path=FullName}" >

The XAML for it working with a list view is the following..

<ListView 
     AlternationCount="2" 
     DataContext="{StaticResource WorkorderGroups}" 
     ItemContainerStyle="{StaticResource WorkorderItemStyle}"
     ItemsSource="{Binding}"
     Grid.Row="2" Grid.ColumnSpan="3" Margin="1,0,-1,0>

     <ListView.GroupStyle>
            <StaticResourceExtension ResourceKey="WorkorderGroupStyle/>
     </ListView.GroupStyle>

        <ListView.View>
            <GridView>
                <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=FullName}" /> 
            </GridView>
        </ListView.View>
    </ListView>
1
Please post more code... - Ayyappan Subramanian

1 Answers

1
votes

You cannot Bind a string to ComboBox. You need to bind some collection like List<T> or ObservableCollection<T> to combobox ItemsSource. Possible Duplicate. Refer the link. Need SIMPLE working example of setting WPF MVVM ComboBox ItemsSource based on SelectedValue of second ComboBox