Introduction to Binding ComboBox and DataGrid Controls in Silverlight 2.0 - Binding Object Collections to Silverlight 2.0 ComboBox cascading with DataGrid
(Page 5 of 6 )
In the previous example, we saw the collection being bound to the ComboBox dynamically. In this section, we will have related binding between a ComboBox and DataGrid.
The following is the Silverlight 2.0 markup which displays both ComboBox and DataGrid in a detailed fashion:
<UserControl x:Class="DemoSL.Page8"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data">
<StackPanel x:Name="LayoutRoot" Background="White">
<StackPanel Height="36" Width="301" Orientation="Horizontal" HorizontalAlignment="Left" Margin="10,0,0,0">
<TextBlock Height="16" x:Name="lblDept" Width="100" Text="Select Dept:" TextWrapping="Wrap"/>
<ComboBox Height="20" x:Name="cboDept" Width="184" Canvas.ZIndex="100" DisplayMemberPath="Dname" />
</StackPanel>
<TextBlock Height="26" HorizontalAlignment="Left" x:Name="lblMsg" Width="350" Text="" TextWrapping="Wrap" Margin="10,0,0,0"/>
<ScrollViewer Height="243" HorizontalAlignment="Stretch" Width="Auto" Margin="10,0,0,0">
<data:DataGrid x:Name="dgEmployees"/>
</ScrollViewer>
</StackPanel>
</UserControl>
You can copy the entire code from the previous section and modify as follows:
Partial Public Class Page8
Inherits UserControl
.
.
Private Sub EmpListFetched(ByVal sender As Object, ByVal e As EmpService.GetEmployeeListByDeptCompletedEventArgs)
Me.dgEmployees.ItemsSource = e.Result
Me.lblMsg.Text = "Fetched!"
End Sub
End Class
It should give the output as follows:

Next: Detailed Explanation >>
More BrainDump Articles
More By Jagadish Chaterjee