I currently have a Combo box that has data that is bind from a database:
<ComboBox x:Name="bookingComboBox"
ItemsSource="{Binding ElementName=bookingDomainDataSource, Path=Data}"
Height="20"
VerticalAlignment="Top"
Margin="387,79,114,0">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Width="150"
Text="{Binding Path=bookingName}" />
<TextBlock Text="{Binding Path=bookingDate, StringFormat=d MMMM yyyy}"
Width="100" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
I also have the datagrid:
<sdk:DataGrid AutoGenerateColumns="False"
Height="200"
HorizontalAlignment="Left"
ItemsSource="{Binding Data, ElementName=bookingDomainDataSource}"
Margin="147,132,0,0"
x:Name="bookingDataGrid"
RowDetailsVisibilityMode="VisibleWhenSelected"
VerticalAlignment="Top"
Width="400">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn x:Name="bookingIdColumn"
Binding="{Binding bookingId, Mode=OneWay}"
Header="Booking Id"
IsReadOnly="True"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="bookingNameColumn"
Binding="{Binding bookingName}"
Header="Booking Name"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="bookingDateColumn"
Binding="{Binding bookingDate}"
Header="Booking Date"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="paymentIdColumn"
Binding="{Binding paymentId}"
开发者_开发知识库 Header="Payment Id"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="showIdColumn"
Binding="{Binding showId}"
Header="Show Id"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="ticketIdColumn"
Binding="{Binding ticketId}"
Header="Ticket Id"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="ticketQuantityColumn"
Binding="{Binding ticketQuantity}"
Header="Ticket Quantity"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="userIdColumn"
Binding="{Binding userId}"
Header="User Id"
Width="SizeToHeader" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
I would like the data grid to change to the row of the row set from the combobox.
How can I do this?
Thanks
If all controls are bound to the same source you should be able to use the following property:
IsSynchronizedWithCurrentItem="True"
Which should be set on both the ComboBox and the DataGrid.
The ItemsSource property must be set to a collection (IEnumerable). What would it mean to set the ItemsSource to a non-collection object? It wouldn't be a "source" of items.
The easiest way to do what you're asking for would be to bind the data grid's ItemsSource to the ComboBox's SelectedItem property. If you want the grid to show child data of the selected item in the combo box, try something like ItemsSource="{Binding ElementName=bookingComboBox, Path=SelectedItem.CHILD_DATA_PROPERTY}".
精彩评论