1

I have a DataGridTextColumn binded with a CompositeCollection of 4 ObservableCollection

One of the DataGridTextColumn, binded like this:

<DataGrid x:Name="DonneesBrutes" IsReadOnly="True" ItemsSource="{Binding Path=.cmpc}" Margin="10,65,0,0" AutoGenerateColumns="False" EnableRowVirtualization="True" RowDetailsVisibilityMode="VisibleWhenSelected">
            <DataGrid.Columns>
                <DataGridTextColumn x:Name="Ligne" Width="*"  Binding="{Binding Path=.Remarque}" Header="Ligne" IsReadOnly="True"></DataGridTextColumn>

Where cmpc is my CompositeCollection and Where Ligne mustn't get a null value. Problem, I takes a lot of null values like in this screen shot: http://www.zimagez.com/zimage/compositecollection.php How can I ignore every lines where it has a null value? Is something like IsNullAble = false exists for a DataGridTextColumn?

Kraenys
  • 297
  • 1
  • 5
  • 19

1 Answers1

2

Here's a simple example (Tested). You will not see the second row because of the trigger. I'm using int values so I'm comparing to 20 in trigger. in your case, use x:Null. You can use the same technique with yours.

XAML :

<Window x:Class="DataGridTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dataGridTest="clr-namespace:DataGridTest"
        Title="MainWindow" Height="350" Width="525">
    <DataGrid AutoGenerateColumns="True">
    <DataGrid.RowStyle>
        <Style TargetType="{x:Type DataGridRow}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding X}" Value="20">
                    <Setter Property="Visibility" Value="Collapsed"></Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>

        <DataGrid.Items>
            <dataGridTest:Test X="10" Y="5" />
            <dataGridTest:Test X="20" Y="10" />
        </DataGrid.Items>
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding X}" />
            <DataGridTextColumn Binding="{Binding Y}" />
        </DataGrid.Columns>
    </DataGrid>
</Window>

Code behind:

namespace DataGridTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }

    public class Test
    {
        public int X { get; set; }
        public int Y { get; set; }
    }
}
nakiya
  • 14,063
  • 21
  • 79
  • 118
  • The first thing I see is the `AutoGenerateColumns="True"` I cannot do this because the columns are generated by my binding from the `CompositeCollection`, I can't (I suppose) Auto Generate'em. Moreover, I don't really understood what you did. Is this working only for the 20 first values? (Sorry, I'm quite new on c# developping) Thank you for your help @Nikaya – Kraenys Sep 12 '14 at 09:35
  • 1
    You don't need to care about other stuff. Just have a look at the `DataTrigger` for the `DataGrid.RowStyle`. Change the `DataTrigger` to something like `Binding="{Binding Remarque}"` and `Value="{x:Null}"`. – nakiya Sep 12 '14 at 09:49
  • It's perfect, was what I was looking for. I'll take a look about the RowStyle and Trigger properties to fully understand what can we do with. – Kraenys Sep 12 '14 at 10:53