Welcome to the Xceed Community | Help
Community Search  
More Search Options

Change cell background based on cell value when binding to a DataTable

Sort Posts: Previous Next
  •  01-31-2009, 7:42 AM Post no. 18318

    Change cell background based on cell value when binding to a DataTable

    Hi,
    I have read several posts about this operation but unfortunately I could not find one that matches what I am trying to do.
    I have a DataTable with a variable number of columns and rows that I am binding to the DataGridControl. If any cell is set to 1.0 (double, not string) I need to change its background color to Red. I don't know the names of the columns in advance (the user basically loads some data from his or hers database so I don't know at dev time what is being loaded).
    I was using Microsoft's grid and solved the problem by changing the Cell style coupled with MultiBinding (I blogged about it here, in case it helps to explain what I am trying to do). It appears I cannot follow the same strategy here.
    I tried using a DataTrigger as suggested in another post but got stuck in the Path:
    <Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},
            Path=what shall I put here???}" Value="1.0">
            <Setter Property="Background" Value="Red"></Setter>
        </DataTrigger>
    </Style.Triggers> 
    Could you please help?
    Thanks
    Jose 
    Filed under: ,
  •  02-03-2009, 1:19 PM Post no. 18364 in reply to 18318

    Re: Change cell background based on cell value when binding to a DataTable

    Hi Jose,

    you could use the following Style to set the Background of a DataCell to Red when its Content value is equal to a double 1.0:

     <Style TargetType="xcdg:DataCell">

       <Style.Triggers>

          <Trigger Property="Content">

             <Trigger.Value>

                <s:Double>1.0</s:Double>

             </Trigger.Value>

     

             <Setter Property="Background"

                     Value="Red" />

          </Trigger>

       </Style.Triggers>

    </Style>

     


    Xceed - Software Developer and Technical Support
  •  02-05-2009, 5:36 AM Post no. 18423 in reply to 18364

    Re: Change cell background based on cell value when binding to a DataTable

    Hi Mohamed,

    Thanks for that it works perfectly. I was really making it too complicated :-)

    Cheers,Jose

  •  02-08-2009, 2:41 PM Post no. 18478 in reply to 18364

    Re: Change cell background based on cell value when binding to a DataTable

    Hi

    I wanted to change it dynamically as my datatable value changes based on some color dictionary

    so as user updates the dictionary with some new color i need to color the cell background.

    Have you got an event for this.

    Please need urgent help

    Thanks in advance

    Indiana  

    Filed under: ,
  •  02-09-2009, 5:39 AM Post no. 18483 in reply to 18478

    Re: Change cell background based on cell value when binding to a DataTable

    If you have the Value defined as {DynamicResource myCellBackground} and a <SolidColorBrush x:Key="myCellBackground">DarkBlue</SolidColorBrush> defined in a ResourceDictionary, if should work.

    When you change ResourceDictionary, it should change.

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.