C
creaves0622
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor
information and the details loads the documents for that vendor in a
datagrid. Everything is working fine until I click in the child datagrid and
then go to the combobox and choose another vendor. When the new vendor is
loaded nothing shows in the datagrid but the itemsource shows the info is
there. Know if I click on the child cell and then click back on the parent
cell everything works fine.
I need to either select a cell programmatically from the parent datagrid to
change the focus back on that, or fix the problem with the datagrid not
showing up
XAML
XAML
<UserControl
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" x:Class="ITAccountReport.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25"/>
<ColumnDefinition Width="380"/>
<ColumnDefinition Width="260"/>
<ColumnDefinition Width="260"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="25"/>
</Grid.ColumnDefinitions>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#3E5f8a" Offset="0.259"/>
<GradientStop Color="#FFFFFFFF" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<TextBlock x:Name="txtVendorName" HorizontalAlignment="Left"
Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Text="Vendor Name"
Width="Auto" Foreground="White" Margin="0,0,0,0"/>
<ComboBox x:Name="cbVendorName" HorizontalAlignment="Left"
Margin="80,0,0,0" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
Width="300" />
<TextBlock Grid.Row="0" Grid.Column="2" HorizontalAlignment="left"
x:Name="txtSelectStartDate" Foreground="White" Text="Select Start Date"/>
<basicsatePicker Grid.Row="0" HorizontalAlignment="Left"
Margin="100,0,0,0" Grid.Column="2" x:Name="dtStartDate" Width="150" />
<TextBlock Grid.Row="0" Grid.Column="3" HorizontalAlignment="Left"
x:Name="txtSelectEndDate" Text="Select End Date" Foreground="White" />
<basicsatePicker Grid.Row="0" HorizontalAlignment="Left"
Margin="100,0,0,0" Grid.Column="3" x:Name="dtEndDate" Width="150" />
<Button x:Name="Search" Content="Search" HorizontalAlignment="Left"
Grid.Column="4" Grid.ColumnSpan="2"/>
<dataataGrid x:Name="FolderDatagrid"
AutoGenerateColumns="False" IsReadOnly="True" Grid.Row="1" Grid.Column="1"
Grid.ColumnSpan="4">
<dataataGrid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="white" Offset="0.259"/>
<GradientStop Color="#C1C1C1" Offset="1"/>
</LinearGradientBrush>
</dataataGrid.Background>
<dataataGrid.Columns>
<dataataGridTextColumn Header="Folder Number"
Binding="{Binding FLD_RSN}" Visibility="Collapsed" />
<dataataGridTextColumn Header="Vendor ID" Width="100"
Binding="{Binding A_VENDOR_ID}" />
<dataataGridTextColumn Header="Vendor Name" Width="200"
Binding="{Binding A_VENDOR_NAME}" />
<dataataGridTextColumn Header="Vendor Desc" Width="500"
Binding="{Binding A_VDR_DESC}" />
</dataataGrid.Columns>
<dataataGrid.RowDetailsTemplate>
<DataTemplate>
<dataataGrid x:Name="DocumentDataGrid"
AreRowDetailsFrozen="True" RowDetailsVisibilityMode="Collapsed"
HorizontalGridLinesBrush="Black" GridLinesVisibility="All"
BorderBrush="Black" BorderThickness="2" AutoGenerateColumns="FALSE"
ItemsSource="{Binding CAWDOCUMENT}" Height="419" Margin="0,-5,0,0"
IsReadOnly="True" VerticalAlignment="Bottom" >
<dataataGrid.Background>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="#C1C1C1" Offset="0.259"/>
<GradientStop Color="#FFFFFFFF" Offset="1"/>
</LinearGradientBrush>
</dataataGrid.Background>
<dataataGrid.Columns>
<dataataGridTextColumn Header="DOC_RSN"
Binding="{Binding DOC_RSN}" Visibility="Collapsed" />
<dataataGridTextColumn Header="DOC TYPE"
Width="100" Binding="{Binding DOC_TYPE}" />
<dataataGridTextColumn Header="DOC
Description" Width="200" Binding="{Binding DOC_DESC}" />
<dataataGridTextColumn Header="Check Number"
Width="100" Binding="{Binding A_CHECK_NO}" />
<dataataGridTextColumn Header="Amount"
Width="100" Binding="{Binding A_AMOUNT}"/>
<dataataGridTextColumn Header="Check Date"
Width="600" Binding="{Binding A_CHECK_DATE}"/>
<dataataGridTemplateColumn Header="Image"
Width="100">
<dataataGridTemplateColumn.CellTemplate>
<DataTemplate>
<HyperlinkButton Content="Image"
TargetName="Image" Foreground="White" NavigateUri="{Binding IMAGE_FILE}">
<HyperlinkButton.Background >
<LinearGradientBrush
EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop
Color="#3E5f8a" Offset="0.259"/>
<GradientStop
Color="#FFFFFFFF" Offset="1"/>
</LinearGradientBrush>
</HyperlinkButton.Background>
</HyperlinkButton>
</DataTemplate>
</dataataGridTemplateColumn.CellTemplate>
</dataataGridTemplateColumn>
</dataataGrid.Columns>
</dataataGrid>
</DataTemplate>
</dataataGrid.RowDetailsTemplate>
</dataataGrid>
</Grid>
</UserControl>
Code Behind
Imports System.Windows.Data
Partial Public Class Page
Inherits UserControl
Dim ClientHost As ServiceReference1.Service1Client = New
ServiceReference1.Service1Client
Dim dg As New DataGrid
Dim folderrow As ServiceReference1.CAWFOLDER
Public Sub New()
InitializeComponent()
AddHandler ClientHost.GetVendorCompleted, AddressOf
ClientHost_GetVendorCompleted
ClientHost.GetVendorAsync()
End Sub
Private Sub ClientHost_GetVendorCompleted(ByVal sender As Object, ByVal
e As ServiceReference1.GetVendorCompletedEventArgs)
If Not e.Result Is Nothing Then
For Each item In e.Result
cbVendorName.Items.Add(item)
Next
End If
End Sub
Private Sub cbVendorName_SelectionChanged(ByVal sender As Object, ByVal
e As System.Windows.Controls.SelectionChangedEventArgs) Handles
cbVendorName.SelectionChanged
AddHandler ClientHost.GetVendorInfoCompleted, AddressOf
ClientHost_GetVendorInfoCompleted
ClientHost.GetVendorInfoAsync(cbVendorName.SelectedItem.ToString)
End Sub
Private Sub ClientHost_GetVendorInfoCompleted(ByVal sender As Object,
ByVal e As ServiceReference1.GetVendorInfoCompletedEventArgs)
If Not e.Result Is Nothing Then
FolderDatagrid.ItemsSource = e.Result
End If
End Sub
Private Sub FolderDatagrid_LoadingRowDetails(ByVal sender As Object,
ByVal e As System.Windows.Controls.DataGridRowDetailsEventArgs) Handles
FolderDatagrid.LoadingRowDetails
FolderDatagrid.SelectedIndex = e.Row.GetIndex
AddHandler ClientHost.GetVendorDocsCompleted, AddressOf
clientHost_GetVendorDocCompleted
Dim row As ServiceReference1.CAWFOLDER = FolderDatagrid.SelectedItem()
folderrow = row
If Not row Is Nothing Then
dg = e.DetailsElement.FindName("DocumentDataGrid")
ClientHost.GetVendorDocsAsync(row.FLD_RSN)
End If
End Sub
Private Sub clientHost_GetVendorDocCompleted(ByVal sender As Object,
ByVal e As ServiceReference1.GetVendorDocsCompletedEventArgs)
If Not e.Result Is Nothing Then
dg.ItemsSource = e.Result
End If
End Sub
End Class
information and the details loads the documents for that vendor in a
datagrid. Everything is working fine until I click in the child datagrid and
then go to the combobox and choose another vendor. When the new vendor is
loaded nothing shows in the datagrid but the itemsource shows the info is
there. Know if I click on the child cell and then click back on the parent
cell everything works fine.
I need to either select a cell programmatically from the parent datagrid to
change the focus back on that, or fix the problem with the datagrid not
showing up
XAML
XAML
<UserControl
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" x:Class="ITAccountReport.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25"/>
<ColumnDefinition Width="380"/>
<ColumnDefinition Width="260"/>
<ColumnDefinition Width="260"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="25"/>
</Grid.ColumnDefinitions>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#3E5f8a" Offset="0.259"/>
<GradientStop Color="#FFFFFFFF" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<TextBlock x:Name="txtVendorName" HorizontalAlignment="Left"
Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Text="Vendor Name"
Width="Auto" Foreground="White" Margin="0,0,0,0"/>
<ComboBox x:Name="cbVendorName" HorizontalAlignment="Left"
Margin="80,0,0,0" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
Width="300" />
<TextBlock Grid.Row="0" Grid.Column="2" HorizontalAlignment="left"
x:Name="txtSelectStartDate" Foreground="White" Text="Select Start Date"/>
<basicsatePicker Grid.Row="0" HorizontalAlignment="Left"
Margin="100,0,0,0" Grid.Column="2" x:Name="dtStartDate" Width="150" />
<TextBlock Grid.Row="0" Grid.Column="3" HorizontalAlignment="Left"
x:Name="txtSelectEndDate" Text="Select End Date" Foreground="White" />
<basicsatePicker Grid.Row="0" HorizontalAlignment="Left"
Margin="100,0,0,0" Grid.Column="3" x:Name="dtEndDate" Width="150" />
<Button x:Name="Search" Content="Search" HorizontalAlignment="Left"
Grid.Column="4" Grid.ColumnSpan="2"/>
<dataataGrid x:Name="FolderDatagrid"
AutoGenerateColumns="False" IsReadOnly="True" Grid.Row="1" Grid.Column="1"
Grid.ColumnSpan="4">
<dataataGrid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="white" Offset="0.259"/>
<GradientStop Color="#C1C1C1" Offset="1"/>
</LinearGradientBrush>
</dataataGrid.Background>
<dataataGrid.Columns>
<dataataGridTextColumn Header="Folder Number"
Binding="{Binding FLD_RSN}" Visibility="Collapsed" />
<dataataGridTextColumn Header="Vendor ID" Width="100"
Binding="{Binding A_VENDOR_ID}" />
<dataataGridTextColumn Header="Vendor Name" Width="200"
Binding="{Binding A_VENDOR_NAME}" />
<dataataGridTextColumn Header="Vendor Desc" Width="500"
Binding="{Binding A_VDR_DESC}" />
</dataataGrid.Columns>
<dataataGrid.RowDetailsTemplate>
<DataTemplate>
<dataataGrid x:Name="DocumentDataGrid"
AreRowDetailsFrozen="True" RowDetailsVisibilityMode="Collapsed"
HorizontalGridLinesBrush="Black" GridLinesVisibility="All"
BorderBrush="Black" BorderThickness="2" AutoGenerateColumns="FALSE"
ItemsSource="{Binding CAWDOCUMENT}" Height="419" Margin="0,-5,0,0"
IsReadOnly="True" VerticalAlignment="Bottom" >
<dataataGrid.Background>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="#C1C1C1" Offset="0.259"/>
<GradientStop Color="#FFFFFFFF" Offset="1"/>
</LinearGradientBrush>
</dataataGrid.Background>
<dataataGrid.Columns>
<dataataGridTextColumn Header="DOC_RSN"
Binding="{Binding DOC_RSN}" Visibility="Collapsed" />
<dataataGridTextColumn Header="DOC TYPE"
Width="100" Binding="{Binding DOC_TYPE}" />
<dataataGridTextColumn Header="DOC
Description" Width="200" Binding="{Binding DOC_DESC}" />
<dataataGridTextColumn Header="Check Number"
Width="100" Binding="{Binding A_CHECK_NO}" />
<dataataGridTextColumn Header="Amount"
Width="100" Binding="{Binding A_AMOUNT}"/>
<dataataGridTextColumn Header="Check Date"
Width="600" Binding="{Binding A_CHECK_DATE}"/>
<dataataGridTemplateColumn Header="Image"
Width="100">
<dataataGridTemplateColumn.CellTemplate>
<DataTemplate>
<HyperlinkButton Content="Image"
TargetName="Image" Foreground="White" NavigateUri="{Binding IMAGE_FILE}">
<HyperlinkButton.Background >
<LinearGradientBrush
EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop
Color="#3E5f8a" Offset="0.259"/>
<GradientStop
Color="#FFFFFFFF" Offset="1"/>
</LinearGradientBrush>
</HyperlinkButton.Background>
</HyperlinkButton>
</DataTemplate>
</dataataGridTemplateColumn.CellTemplate>
</dataataGridTemplateColumn>
</dataataGrid.Columns>
</dataataGrid>
</DataTemplate>
</dataataGrid.RowDetailsTemplate>
</dataataGrid>
</Grid>
</UserControl>
Code Behind
Imports System.Windows.Data
Partial Public Class Page
Inherits UserControl
Dim ClientHost As ServiceReference1.Service1Client = New
ServiceReference1.Service1Client
Dim dg As New DataGrid
Dim folderrow As ServiceReference1.CAWFOLDER
Public Sub New()
InitializeComponent()
AddHandler ClientHost.GetVendorCompleted, AddressOf
ClientHost_GetVendorCompleted
ClientHost.GetVendorAsync()
End Sub
Private Sub ClientHost_GetVendorCompleted(ByVal sender As Object, ByVal
e As ServiceReference1.GetVendorCompletedEventArgs)
If Not e.Result Is Nothing Then
For Each item In e.Result
cbVendorName.Items.Add(item)
Next
End If
End Sub
Private Sub cbVendorName_SelectionChanged(ByVal sender As Object, ByVal
e As System.Windows.Controls.SelectionChangedEventArgs) Handles
cbVendorName.SelectionChanged
AddHandler ClientHost.GetVendorInfoCompleted, AddressOf
ClientHost_GetVendorInfoCompleted
ClientHost.GetVendorInfoAsync(cbVendorName.SelectedItem.ToString)
End Sub
Private Sub ClientHost_GetVendorInfoCompleted(ByVal sender As Object,
ByVal e As ServiceReference1.GetVendorInfoCompletedEventArgs)
If Not e.Result Is Nothing Then
FolderDatagrid.ItemsSource = e.Result
End If
End Sub
Private Sub FolderDatagrid_LoadingRowDetails(ByVal sender As Object,
ByVal e As System.Windows.Controls.DataGridRowDetailsEventArgs) Handles
FolderDatagrid.LoadingRowDetails
FolderDatagrid.SelectedIndex = e.Row.GetIndex
AddHandler ClientHost.GetVendorDocsCompleted, AddressOf
clientHost_GetVendorDocCompleted
Dim row As ServiceReference1.CAWFOLDER = FolderDatagrid.SelectedItem()
folderrow = row
If Not row Is Nothing Then
dg = e.DetailsElement.FindName("DocumentDataGrid")
ClientHost.GetVendorDocsAsync(row.FLD_RSN)
End If
End Sub
Private Sub clientHost_GetVendorDocCompleted(ByVal sender As Object,
ByVal e As ServiceReference1.GetVendorDocsCompletedEventArgs)
If Not e.Result Is Nothing Then
dg.ItemsSource = e.Result
End If
End Sub
End Class