Red border surrounding cell overlaps row header when scrolling - wpf

I’m having a problem while using the DataGrid object with row headers.
Each row of the table contains an object that implements the iDataErrorInfo interface and when a cell has an error and a horizontal scroll happens, the red border of the cell overlaps the row header.
How can I solve the problem and avoid the overlapping?
<DataGrid ItemsSource="{Binding Customers}"
AutoGenerateColumns="False"
RowHeaderWidth="200"
CanUserResizeColumns="False"
HeadersVisibility="All">
<DataGrid.Columns>
<DataGridTextColumn Header="FirstName"
Binding="{Binding Path=FirstName, ValidatesOnDataErrors=True}"
Width="700" />
<DataGridTextColumn Header="LastName"
Binding="{Binding Path=LastName, ValidatesOnDataErrors=True}"
Width="700" />
<DataGridTextColumn Header="FullName"
Binding="{Binding Path=FullName, ValidatesOnDataErrors=True}"
Width="700" />
</DataGrid.Columns>
</DataGrid>

Related

WPF Datagrid RowDetails display disable for specific column click

I'm hoping this is possible to do using XAML only.
I have a Datagrid containing 3 DataGridTextColumns and 1 DataGridComboBoxColumn, the RowDetailsTemplate display when on a single-click of any DataGridCell, the problem is it displays when I click on the DataGridComboBoxColumn, I'd like to disable the showing of the RowDetailsTemplate for this column only. I've seen solutions involving adding events to DataGrid cells and then showing/hiding the row using the code-behind file but would prefer this to be a XAML only solution if possible
<DataGrid
ItemsSource="{Binding Employees}"
Background="Transparent"
CanUserAddRows="False"
CanUserResizeColumns="False"
CanUserResizeRows="False"
SelectionUnit="FullRow"
SelectionMode="Extended"
AutoGenerateColumns="False"
HeadersVisibility="Column"
Grid.Row="1">
<DataGrid.Columns>
<DataGridTextColumn Header="Email" Binding="{Binding Email}"/>
<DataGridTextColumn Header="First Name" Binding="{Binding FirstName}"/>
<DataGridTextColumn Header="Last Name" Binding="{Binding LastName}"/>
<DataGridComboBoxColumn ItemsSource="{Binding Departments}"/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<TextBlock Text="ROW DETAILS HERE"/>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>

WPF DataGridCheckBoxColumn not clickable when using MVVM

I have the following datagrid
<DataGrid
Grid.Column="0"
Grid.Row="1"
CanUserAddRows="False"
CanUserDeleteRows="False"
AutoGenerateColumns="False"
SelectionUnit="FullRow"
SelectionMode="Single"
Height="auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.CanContentScroll="True"
ItemsSource="{Binding TableSummaries }">
<DataGrid.Columns>
<DataGridCheckBoxColumn Width="*" Binding="{Binding IsChecked}"/>
<DataGridTextColumn Header="Source Table" Binding="{Binding SourceTableFullName}" Width="4*"></DataGridTextColumn>
<DataGridTextColumn Header="EDW Schema" Binding="{Binding SchemaName}" Width="2*"></DataGridTextColumn>
<DataGridTextColumn Header="EDW Table" Binding="{Binding TableName}" Width="4*"></DataGridTextColumn>
<DataGridTextColumn Header="Status" Binding="{Binding Status}" Width="*"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
and int the viewmodel i have the property
public bool IsChecked { get; set; }
when the application is running the check boxes show up but they are not clickable. i can't check them or do anything to them
Am i missing something?
thanks!
UPDATE:
I added IsReadOnly = "false" to the datagrid to just see if that was it and still same result.
What if you used a template column instead
<DataGridTemplateColumn Header="CheckBox" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Binding="{Binding IsChecked, Mode=TwoWay}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Does that work?
Also, do you get any binding errors in your output window when you run the application and have you implemented INotifyPropertyChanged?
I found the issue TableSummaries was an IEumerable and it needed to implement IList and it worked just fine.

Daughter DataGrid.Columns fill all the available width

There is my layout:
<DataGrid x:Name="BooksGrid"
DataContext="{Binding WorkingBooksSet, Mode=TwoWay}"
ItemsSource="{Binding}"
RowDetailsVisibilityMode="VisibleWhenSelected"
AutoGenerateColumns="False"
VerticalAlignment="Top" HorizontalAlignment="Stretch"
ColumnWidth="*">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Id}" Width="Auto" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Title}" />
...
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid ItemsSource="{Binding Publications, Mode=TwoWay}"
AutoGenerateColumns="False"
VerticalAlignment="Top" HorizontalAlignment="Stretch"
ColumnWidth="*">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Id}" Width="Auto" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Publisher}" />
<DataGridTextColumn Binding="{Binding ReleaseYear}" />
...
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
And it's a window
As you can see, daughter DataGrid for some reason has not filled all the available space, instead made ​​them narrow. Moreover it is prohibited to manually resize the columns.
I do not understand this behavior, especially as the "parent" DataGrid displays correctly with the same code
Add * width to one of the columns in your child DataGrid.
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Id}" Width="Auto" IsReadOnly="True" />
<DataGridTextColumn Binding="{Binding Publisher}" />
<DataGridTextColumn Binding="{Binding ReleaseYear}" Width="*" />
...
</DataGrid.Columns>

WPF datagrid in usercontrol

<DataGrid Width="auto" AutoGenerateColumns="False" Name="dgData" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding HODAppID}" Width="75" Header="HOD APPID" />
<DataGridTextColumn Binding="{Binding Req}" Header="CandidateID" Visibility="Hidden" />
<DataGridTextColumn Binding="{Binding Req}" Header="RequisitionNo" Visibility="Hidden" />
<DataGridTextColumn Binding="{Binding Candidate}" Width="1.3*" Header="CANDIDATE NAME" />
<DataGridTextColumn Binding="{Binding Req}" Width="*" MinWidth="200" Header="REQUIREMENT"/>
<DataGridTextColumn Binding="{Binding status}" Width="80" Header="Status" />
<DataGridTextColumn Binding="{Binding daysopen}" Width="120" x:Name="noDays" Header="# of Days Open" />
hi i have a datagrid , something like above, i was trying to get cell value in column noDays, and change the fore color based on the value in it.please help in this regard.Thanks in advance
Create a converter using IValueConverter and add it to your noDays column Foreground property. The converter should return a brush value based on the value of the daysopen property.
http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx
EDIT:
Apparently IValueConverter doesn't work straight on DataGridTextColumn. More info and an example can be found at http://social.msdn.microsoft.com/Forums/en/wpf/thread/77a9f317-d0be-4aed-9dc9-9917ad98ffc8.

Render custom XAML inside cells of a particular column in WPF

I have a DataGrid and I would like to have my first column's cells all render some custom XAML.
Currently I have just the grid:
<DataGrid CanUserSortColumns="False" SelectionUnit="FullRow" HeadersVisibility="Column" ItemsSource="{Binding Test}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=Foo}" Header="Foo"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Path=Bar}" Header="Bar"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
For starters, I would like to be able to add some specific WPF control/XAML into the first column's cells.
You just need to use a DataGridTemplateColumn with a CellTemplate:
<DataGridTemplateColumn Header="Foo">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Foo}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Resources