Reputation: 616
I have a DataGrid
that i am trying to change the selected item by selecting the row and not the cell. As you can see from the image below when i click outside the cell the item doesn't update.
<DataGrid x:Name="customerListBox" SelectedItem="{Binding SelectedCustomer, UpdateSourceTrigger=PropertyChanged}" SelectionMode="Single" IsReadOnly="True" ItemsSource="{Binding Customers}" Margin="10,57,10,10" AlternationCount="2" BorderThickness="1" SnapsToDevicePixels="True" AutoGenerateColumns="False" BorderBrush="Black" Foreground="Black">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Id}" Header="Id"/>
<DataGridTextColumn Binding="{Binding Name}" Header="Name"/>
<DataGridTextColumn Binding="{Binding Phone}" Header="Phone"/>
<DataGridTextColumn Binding="{Binding Email}" Header="Email"/>
</DataGrid.Columns>
</DataGrid>
What i can do to get it working is setting the last column width to *
However this makes the header central and looks messy when displayed on a wide screen monitor.
<DataGridTextColumn Binding="{Binding Email}" Width="*" Header="Email"/>
Upvotes: 5
Views: 2219
Reputation: 503
I have workaround to fix this issue, just add dummy empty column after the last column with Width="*"
Upvotes: 4
Reputation: 1703
Have you tried this ?
customerListBox.SelectionUnit = DataGridSelectionUnit.FullRow;
You can also use
customerListBox.SelectionMode = DataGridSelectionMode.Extended;
To allow multiple selection if you need
Upvotes: 1