Click here to Skip to main content
15,894,410 members
Home / Discussions / WPF
   

WPF

 
QuestionComboBox + 2 DataSet/DataTable (ItemSource and SelectedValue) DataBinding Problem Pin
awilkens20-Feb-09 0:28
awilkens20-Feb-09 0:28 
Questionclipping an image region and saving as new image Pin
coolpjmartin20-Feb-09 0:21
coolpjmartin20-Feb-09 0:21 
AnswerRe: clipping an image region and saving as new image Pin
sivaddrahcir20-Feb-09 11:08
sivaddrahcir20-Feb-09 11:08 
QuestionInfragistics WPF Pin
rastaVnuce19-Feb-09 11:25
rastaVnuce19-Feb-09 11:25 
AnswerRe: Infragistics WPF Pin
rastaVnuce19-Feb-09 22:05
rastaVnuce19-Feb-09 22:05 
QuestionStyling GroupBox dynamically Pin
vsaratkar19-Feb-09 9:43
vsaratkar19-Feb-09 9:43 
AnswerRe: Styling GroupBox dynamically [modified] Pin
Mark Salsbery19-Feb-09 15:37
Mark Salsbery19-Feb-09 15:37 
QuestionCombobox in Listview Pin
Rolorob19-Feb-09 3:25
Rolorob19-Feb-09 3:25 
Hello,

I have a problem with Binding and a ListView.
I have an order system with Orders and Customers.

I tried to make a sort of Datagrid of the order system with TextBoxes so I can edit all the values.
These bind perfectly.
However, I also want a ComboBox in it, with a drop down of all the customers I have.

The XAML code pasted below here has two parts. One with 3 textfields and this ComboBox I speak of, and 1 containing the DataGrid.
<Window x:Class="WpfLookup.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        
    Title="Window1" Height="320" Width="456" Loaded="Window_Loaded">

    <Grid Height="Auto" Width="Auto" Margin="6">
        <Grid.RowDefinitions>
            <RowDefinition Height="115" />
            <RowDefinition Height="28" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="90" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        
        <StackPanel Name="stackPanel1" Margin="0">
            <Label Height="23" Name="label1" Width="Auto" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right" Margin="3">Order ID</Label>
            <Label Height="23" Name="label3" Width="Auto" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right" Margin="3">Customer</Label>
            <Label Height="23" Name="label2" Width="Auto" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right" Margin="3">Order date</Label>
            <Label Height="23" Name="label4" Width="Auto" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right" Margin="3">Ship date</Label>
        </StackPanel>
        <Button Grid.Column="1" Grid.Row="1" Name="btnAdd" HorizontalAlignment="Right" Width="64" Height="22.745" VerticalAlignment="Bottom" Margin="3" Click="btnAdd_Click">Add</Button>
        <Button Grid.Column="1" Grid.Row="1" Name="btnSave" Margin="0,0,75,3" Click="btnSave_Click" Height="22.745" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="64.163">Save</Button>
        <StackPanel Grid.Column="1" Name="stackPanel2">
           <TextBox 
                Text="{Binding Path=orderID, Mode=OneWay}"
                IsReadOnly="True"
                Height="23" Name="textBox1" Width="Auto" Margin="3" />
            <ComboBox
                SelectedValuePath="customerID"
                SelectedValue="{Binding Path=customerID}"
                
                Height="23" Name="cbCustomer" Width="Auto" Margin="3" SelectionChanged="cbCustomer_SelectionChanged">
                
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="Images/salome.gif" Height="Auto" Width="Auto" MaxHeight="40" MaxWidth="40"/>
                            <TextBlock Name="tbLastName"  VerticalAlignment="Center" Text="{Binding Path=lastName}" />
                            <TextBlock Name="tbComma" VerticalAlignment="Center" Text=", " />
                            <TextBlock Name="tbFirstName" VerticalAlignment="Center" Text="{Binding Path=firstName}" />
                        </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                
            </ComboBox>
            <TextBox 
                Text="{Binding Path=orderDate}"
                Height="23" Name="tbOrderDate" Width="Auto" Margin="3" TextChanged="tbOrderDate_TextChanged" />
            <TextBox 
                Text="{Binding Path=shipDate}"
                Height="23" Name="tbShipDate" Width="Auto" Margin="3" TextChanged="tbShipDate_TextChanged" />
            <TextBox
                Name="tbModified"
                Text="{Binding Path=modified, Mode=OneWayToSource}"
                Visibility="Hidden" />
        </StackPanel>
        <Button Grid.Row="1" Name="btnPrevious" HorizontalAlignment="Left" Width="18.18" Height="22.745" VerticalAlignment="Bottom" Margin="3" Click="btnPrevious_Click">&lt;</Button>
        <Button Grid.Row="1" HorizontalAlignment="Right" Name="btnNext" Width="18.18" Height="22.745" VerticalAlignment="Bottom" Margin="3" Click="btnNext_Click">&gt;</Button>
        
        <ListView Name="testView"
            IsSynchronizedWithCurrentItem="True"
            ItemsSource="{Binding}"
            Grid.Row="2" Grid.Column="2" Margin="3">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                </Style>
            </ListView.ItemContainerStyle>
            
            <ListView.View>
                <GridView>
                    <GridViewColumn 
                        Header="Order ID" DisplayMemberBinding="{Binding Path=orderID, Mode=OneWay}" Width="75"/>
                    <GridViewColumn Header="OrderDate" Width="75">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>  
                                <ComboBox                         
                                    SelectedValuePath="customerID"
                                    SelectedValue="{Binding Path=customerID}"
                                    ItemsSource="{Binding dsCustomer.Customer}"
                                    
                                    Name="cbCustomer2"
                
                                    
                                    Height="23" Width="Auto" Margin="3" SelectionChanged="cbCustomer_SelectionChanged">

                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal">
                                                <Image Source="Images/salome.gif" Height="Auto" Width="Auto" MaxHeight="40" MaxWidth="40"/>
                                                <TextBlock Name="tbLastName"  VerticalAlignment="Center" Text="{Binding Path=lastName}" />
                                                <TextBlock Name="tbComma" VerticalAlignment="Center" Text=", " />
                                                <TextBlock Name="tbFirstName" VerticalAlignment="Center" Text="{Binding Path=firstName}" />
                                            </StackPanel>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>

                                </ComboBox>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="OrderDate" Width="75">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBox
                                    Text="{Binding Path=orderDate}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="Ship date" Width="75">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBox
                                    Text="{Binding Path=shipDate}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                        
                    </GridViewColumn>
                    
                </GridView>
            </ListView.View>         
        </ListView>
    </Grid>
</Window>

If we focus on the first ComboBox:
<ComboBox
                SelectedValuePath="customerID"
                SelectedValue="{Binding Path=customerID}"
                
                Height="23" Name="cbCustomer" Width="Auto" Margin="3" SelectionChanged="cbCustomer_SelectionChanged">
                
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="Images/salome.gif" Height="Auto" Width="Auto" MaxHeight="40" MaxWidth="40"/>
                            <TextBlock Name="tbLastName"  VerticalAlignment="Center" Text="{Binding Path=lastName}" />
                            <TextBlock Name="tbComma" VerticalAlignment="Center" Text=", " />
                            <TextBlock Name="tbFirstName" VerticalAlignment="Center" Text="{Binding Path=firstName}" />
                        </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                
            </ComboBox>

This one works perfectly. But only when I change the ItemsSource in C# code:
this.cbCustomer.ItemsSource = dsCustomer.Customer;

It won't work when I would do it in XAML code:
this.cbCustomer.ItemsSource = dsCustomer.Customer;


Am I doing something wron in the XAML code?
I'm quite new to WPF.

The reason I ask this, is that this ComboBox will return in the datagrid, I can't however name it, because multiple ComboBoxes will be generated, and I don't have the name to use in C# code.

I hope my problem is clear and someone knows what I am doing wrong, thanks in advance for the help. Roll eyes | :rolleyes:
AnswerRe: Combobox in Listview Pin
ABitSmart19-Feb-09 4:05
ABitSmart19-Feb-09 4:05 
GeneralRe: Combobox in Listview [modified] Pin
Rolorob19-Feb-09 4:26
Rolorob19-Feb-09 4:26 
GeneralRe: Combobox in Listview Pin
ABitSmart19-Feb-09 5:16
ABitSmart19-Feb-09 5:16 
GeneralRe: Combobox in Listview Pin
Rolorob19-Feb-09 6:59
Rolorob19-Feb-09 6:59 
GeneralRe: Combobox in Listview [modified] Pin
Rolorob19-Feb-09 20:44
Rolorob19-Feb-09 20:44 
GeneralRe: Combobox in Listview Pin
ABitSmart19-Feb-09 21:19
ABitSmart19-Feb-09 21:19 
GeneralRe: Combobox in Listview Pin
Rolorob19-Feb-09 22:23
Rolorob19-Feb-09 22:23 
GeneralRe: Combobox in Listview Pin
ABitSmart19-Feb-09 22:48
ABitSmart19-Feb-09 22:48 
GeneralRe: Combobox in Listview Pin
Rolorob19-Feb-09 23:01
Rolorob19-Feb-09 23:01 
GeneralRe: Combobox in Listview Pin
ABitSmart19-Feb-09 23:10
ABitSmart19-Feb-09 23:10 
GeneralRe: Combobox in Listview Pin
Rolorob19-Feb-09 23:17
Rolorob19-Feb-09 23:17 
GeneralRe: Combobox in Listview Pin
ABitSmart19-Feb-09 23:51
ABitSmart19-Feb-09 23:51 
GeneralRe: Combobox in Listview [modified] Pin
Rolorob20-Feb-09 0:21
Rolorob20-Feb-09 0:21 
GeneralRe: Combobox in Listview Pin
Rolorob20-Feb-09 1:55
Rolorob20-Feb-09 1:55 
GeneralRe: Combobox in Listview Pin
ABitSmart20-Feb-09 2:15
ABitSmart20-Feb-09 2:15 
GeneralRe: Combobox in Listview Pin
Rolorob20-Feb-09 2:28
Rolorob20-Feb-09 2:28 
GeneralRe: Combobox in Listview Pin
ABitSmart20-Feb-09 2:37
ABitSmart20-Feb-09 2:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.