I have a WPF datagrid that looks like the following:
<DataGrid x:Name="dataGridOrderItems" Margin="369,0,4,51" VerticalAlignment="Bottom" Height="405" Grid.Row="1"
VerticalGridLinesBrush="LightGray" HorizontalGridLinesBrush="LightGray" AlternatingRowBackground="Beige" AlternationCount="2" SelectionMode="Single"
SelectionChanged="dataGridOutstandingOrders_SelectionChanged" AutoGenerateColumns="False" IsReadOnly="True" Grid.ColumnSpan="2">
<DataGrid.Columns>
<DataGridTextColumn Header="Resource Name" Binding="{Binding ResourceName}" />
<DataGridTextColumn Header="Quantity Ordered" Binding="{Binding Quantity}" />
<DataGridTextColumn Header="Order Date" Binding="{Binding OrderDate, StringFormat=\{0:d\}}" />
<DataGridCheckBoxColumn Header="Dispatched Resource" Binding="{Binding IsChecked}" />
<DataGridTextColumn/>
</DataGrid.Columns>
</DataGrid>
Even though the datagrid is enabled and I've specified a selection mode I can't click into any of the cells. What else am I missing?
In case it's relevant, here's the full XAML for the window:
<Window x:Class="OrderProcessor.MainWindow"
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"
xmlns:local="clr-namespace:OrderProcessor"
mc:Ignorable="d"
Title="Order Processing" Height="727.625" Width="1088" Icon="1438333970_Delivery.ico">
<Grid Margin="0,0,2,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="9*"/>
<ColumnDefinition Width="14*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="94*"/>
<RowDefinition Height="315*"/>
</Grid.RowDefinitions>
<Button x:Name="buttonRefreshOrders" Content="Load/Refresh Orders List" Margin="0,36,10,0" RenderTransformOrigin="-0.72,-2.65" ToolTip="Click to refresh the orders list with the latest orders from SharePoint" Grid.Column="1" HorizontalAlignment="Right" Width="140" Height="36" VerticalAlignment="Top" Click="buttonRefreshOrders_Click"/>
<DataGrid x:Name="dataGridOutstandingOrders" Margin="11,7,156,470" RenderTransformOrigin="0.5,0.5" Grid.RowSpan="2" Grid.ColumnSpan="2" VerticalGridLinesBrush="LightGray" HorizontalGridLinesBrush="LightGray" AlternatingRowBackground="Beige" AlternationCount="2" SelectionMode="Single" SelectionUnit="FullRow" SelectionChanged="dataGridOutstandingOrders_SelectionChanged" AutoGenerateColumns="False" IsReadOnly="True">
<DataGrid.Columns>
<DataGridTextColumn Header="Persona" Binding="{Binding Persona }" />
<DataGridTextColumn Header="Customer Name" Binding="{Binding CustomerName }" />
<DataGridTextColumn Header="Organization" Binding="{Binding Organization }" />
<DataGridTextColumn Header="E-mail" Binding="{Binding Email }" />
<DataGridTextColumn Header="Phone" Binding="{Binding PhoneNumber }" />
<DataGridTextColumn Header="Street" Binding="{Binding Street }" />
<DataGridTextColumn Header="Suburb" Binding="{Binding Suburb }" />
<DataGridTextColumn Header="Postcode" Binding="{Binding Postcode }" />
<DataGridTextColumn Header="Order Date" Binding="{Binding OrderDate , StringFormat={}{0:d}}" />
</DataGrid.Columns>
</DataGrid>
<Button x:Name="button_Dispatch_Current_Item" Content="Set selected resources to be dispatched" Margin="0,0,10,10" RenderTransformOrigin="-0.72,-2.65" ToolTip="" HorizontalAlignment="Right" Width="462" Grid.Row="1" Grid.Column="1" Height="36" VerticalAlignment="Bottom"/>
<GroupBox x:Name="groupBoxCustomerDetails" Header="Customer Details" Margin="11,0,0,10" Grid.Row="1"
Grid.Column="0" VerticalAlignment="Bottom" Height="455" HorizontalAlignment="Left" Width="353">
<StackPanel>
<Label x:Name="labelCustomerName" Content="" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="16" FontWeight="Bold"/>
<Label x:Name="labelCustomerOrganization" Content="" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="16" />
<Label x:Name="labelCustomerStreet" Content="" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="16" />
<Label x:Name="labelCustomerSuburb" Content="" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="16" />
<Label x:Name="labelCustomerPostcode" Content="" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="16" />
</StackPanel>
</GroupBox>
<DataGrid x:Name="dataGridOrderItems" Margin="369,0,4,51" VerticalAlignment="Bottom" Height="405" RenderTransformOrigin="0.5,0.5" Grid.Row="1"
VerticalGridLinesBrush="LightGray" HorizontalGridLinesBrush="LightGray" AlternatingRowBackground="Beige" AlternationCount="2" SelectionMode="Single"
SelectionChanged="dataGridOutstandingOrders_SelectionChanged" AutoGenerateColumns="False" IsReadOnly="True" Grid.ColumnSpan="2">
<DataGrid.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform AngleY="-0.146"/>
<RotateTransform/>
<TranslateTransform Y="-0.497"/>
</TransformGroup>
</DataGrid.RenderTransform>
<DataGrid.Columns>
<DataGridTextColumn Header="Resource Name" Binding="{Binding ResourceName}" />
<DataGridTextColumn Header="Quantity Ordered" Binding="{Binding Quantity}" />
<DataGridTextColumn Header="Order Date" Binding="{Binding OrderDate, StringFormat=\{0:d\}}" />
<DataGridCheckBoxColumn Header="Dispatched Resource" Binding="{Binding IsChecked}" />
<DataGridTextColumn/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
Ended up resolving this one myself - it looks like I didn't have both selection modes. Updated (working XAML):
<DataGrid x:Name="dataGridOrderItems" Margin="369,0,4,51" VerticalAlignment="Bottom" Height="405" Grid.Row="1"
VerticalGridLinesBrush="LightGray" HorizontalGridLinesBrush="LightGray" AlternatingRowBackground="Beige" AlternationCount="2"
SelectionMode="Single" SelectionUnit="FullRow"
AutoGenerateColumns="False" IsReadOnly="False" Grid.ColumnSpan="2">
<DataGrid.Columns>
<DataGridTextColumn Header="Resource Name" Binding="{Binding ResourceName}" />
<DataGridTextColumn Header="Quantity Ordered" Binding="{Binding Quantity}" />
<DataGridTextColumn Header="Order Date" Binding="{Binding OrderDate, StringFormat=\{0:d\}}" />
<DataGridCheckBoxColumn Header="Dispatched Resource" Binding="{Binding IsChecked}" />
<DataGridTextColumn/>
</DataGrid.Columns>
</DataGrid>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With