none
WPF c# Highlight datagrid rows in range

    Question

  • Hello Code msdn.
    Need Help. i have datagrid with auto generate columns false. Columns are adding from code behind(bottom i will upload screenshot) So i need to Highlight rows in date range for example from 31/8/2011 04/9/2011 where room number = 777 . I really need a help  please :)

    http://imageshack.us/photo/my-images/641/captureqg.jpg/

    Saturday, July 30, 2011 11:41 PM

Answers

  • Hi Lester555,

    You can use a trigger in DataGrid.CellStyle to set the background color.

    Here is a simple sample.

        <DataGrid>
          <DataGrid.CellStyle>
            <Style TargetType="DataGridCell">
              <Style.Triggers>
                <DataTrigger Binding="{Binding IsBooked}" Value="True">
                  <Setter Property="Background" Value="Blue"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsCheckin}" Value="True">
                  <Setter Property="Background" Value="Red"/>
                </DataTrigger>
              </Style.Triggers>
            </Style>
          </DataGrid.CellStyle>
        </DataGrid>
    

    Best regards,


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 02, 2011 7:25 AM

All replies

  • Hi,

    Please follow this tread

    Applying Filtering and grouping in a WPF Datagrid

    http://social.msdn.microsoft.com/Forums/en/wpf/thread/03972347-969f-4704-9b54-2d13c265fb8f

    Regards


    Md. Masudur Rahman
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    http://munnaondotnet.blogspot.com/
    Sunday, July 31, 2011 5:33 AM
  • Hi Lester555,

    You can use a trigger in DataGrid.CellStyle to set the background color.

    Here is a simple sample.

        <DataGrid>
          <DataGrid.CellStyle>
            <Style TargetType="DataGridCell">
              <Style.Triggers>
                <DataTrigger Binding="{Binding IsBooked}" Value="True">
                  <Setter Property="Background" Value="Blue"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsCheckin}" Value="True">
                  <Setter Property="Background" Value="Red"/>
                </DataTrigger>
              </Style.Triggers>
            </Style>
          </DataGrid.CellStyle>
        </DataGrid>
    

    Best regards,


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 02, 2011 7:25 AM