Datagrid Cell Format

Can somebody please help me out (In WPF for absolute DUMMIES fashion) how I can achieve the following:
I have a DataGrid that I add market data to under the following column Headings:
Updated, Volume, Price
I want to format the volume cell whenever the volume value in that cell is 1) between certain values and 2) Greater than a certain value (Similar to conditional formatting of cells in Excel).
I have tried this:
<DataGridTextColumn.ElementStyle>
                        <Style TargetType="{x:Type TextBlock}">
                            <Style.Triggers>
                                <Trigger Property="Text" Value="10">
                                    <Setter Property="Background" Value="LightGreen"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
But the problem is I need to use 'BETWEEN' and 'GREATER THAN', and as you can see, the Value is '=10'
I have gone through many solutions people have posted using IValueConverter
but I keep getting errors that I can't seem to resolve. Can someone please provide a walkthrough, or a link to a walkthrough in REAL MONKEY STUPID SIMPLE fashion for someone trying to learn WPF. Thank you!

There is no >= operator not <= operator available in XAML so you need to use a converter here.
1. Create a class that implements the IValueConverter. The Convert method should return true or false:
using System;
using System.Windows.Data;
namespace WpfApplication22
class MyConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
decimal d = System.Convert.ToDecimal(value);
return d >= 10;
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
throw new NotImplementedException();
2. Use a DataTrigger in the style that sets the background to some colour if the converter returns true/false:
<DataGrid
xmlns:local="clr-namespace:WpfApplication22" ... >
<DataGrid.Resources>
<local:MyConverter x:Key="conv"/>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Price}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Background" Value="LightGreen"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Price, Converter={StaticResource conv}}" Value="False">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
In the code sample above, the DataGridTextColumn is bound to a source property named "Price" that is of type decimal. You must change the name of the property and the type of d in the Convert method if you are using another name/type.
The Background is set to Red or LightGreen depending on whether the value of the Price source property >= 10.
Please refer to the following links for more information about converters:
https://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter(v=vs.110).aspx
http://www.wpf-tutorial.com/data-binding/value-conversion-with-ivalueconverter/
Hope that helps.
Please remember to close your threads by marking helpful posts as answer and please start a new thread if you have a new question.

Similar Messages

  • Need help with Report Generation Toolkit: Excel Set Cell Format.vi

    Hi people,
    I've been searching and found this old thread of someone asking what is the input parameter "Number format". And I dont know what should I put in there. I've tried so many possibilities, but nothing works so far, such as:
    0,0
    0,?
    0,#
    #,0
    ?,0
    and also with @, doesnt works. Where would I find help about this parameter?
    I'm using Excel2003, german version, thus local decimal separator is a comma.
    I also found this help from NI, but seems doesnt help me either. Do I miss something important?
    thanks,
    Yan. 

    Hi,
    I've used your suggestion and some numbers in excel doesnt need to get "right click, change to numbers" anymore (green indicators on the left-top side in some cells are gone). But, I think its still not a number, because I cant use a simple formula, such as in cell A10 I type "= A1/2" (cell A10 equals cell A1 divided with 2) . I got error which says its not a number.
    Well, but other thing is found, any format-string I put in the input of Excel Set Cell Format.vi, such as #,########, will be shown the same as "customize #,########" if I right click in a cell in excel and click "Zellen formatieren" (formatting cell). But however, the numbers are still depends on the input of the format I put in the Append Table to Report.vi.
    regards,
    Yan.

  • How can I copy cell formatting from one range to another?

    How can I copy cell formatting from one range to another, including text fonts, colours, borders, etc., so that, for example, I can reuse a formatted reconciliation table again in different parts of a sheet?

    Hi George,
    Wayne found the Spinning Beachball of Death, and you will find it too.
    Numbers is not good at handling large datasets. Might I suggest that you group your data into smaller sets (each month, perhaps?) and save each group in a separate Numbers document. Numbers will not link between documents, but you could have a summary Table within each document. Then comes the "clunky" bit of copying all those summary tables into a master document where you do the final processing of the data.
    Regards,
    Ian.

  • How to express cell format in Numbers?

    In Numbers on Mac, I want all positive numbers in cells to display in blue with comma separators and a leading + sign.  Example: the value 4135 should appear as +4,135
    I want all negative numbers in cells to display in red with comma separators and a leading - sign.  Example: the value 2167 should appear as -2,167
    I know how to create this in Excel with the custom format [Blue]+#,##0;[Red]-#,##0
    When I create a spreadsheet in Excel, then open the spreadsheet in Numbers, this cell format is not recognized by Numbers.  Does anyone know how to create this cell format in Numbers?  Thx

    Hi pomme4moi,
    You can get the "+", the "-" and the commas in the custom format menu.
    For you colors you need conditional formatting as shown by Wayne.
    quinn

  • How to enter a value into datagrid cell in wpf through manually?

    Hi,
        Here my datagrid rows are in readonly mode here how can i enter the values in to the datagrid cell.(means how can i edit the cell value).i am adding the value to datagrid through programetically, I think  for this reason my datagrid rows
    are visible in readonly mode. Then how can i edit. Please guide me.
    Regards,
    Bhadram

    Hi Barry,
       Thank you for your reply, Now i sending my sample please check it once and suggest me.
    MainWindow.xaml.cs
    private void Save_Click(object sender, RoutedEventArgs e)
     List<CustomerMainViewModel> customer = new List<CustomerMainViewModel>(); customerviewmodel.NameTextField = tbName.Text;
    customerviewmodel.AddressTextField = tbAddress.Text;
    customerviewmodel.CountryField = countryddl.Text;
    customerviewmodel.StateField = stateddl.Text;
    customerviewmodel.Product = customerviewmodel.Product1 + "," + customerviewmodel.Product2;
    foreach(string str in customerviewmodel.actionCollection)
    customerviewmodel.ActionColl.Add(str);
    customerviewmodel.actionCollection.Clear();
    customer.Add(customerviewmodel);
    dataGrid1.Items.Add(customer);
    MessageBox.Show("Data Successfully Saved", " MessageBox", MessageBoxButton.OK, MessageBoxImage.Asterisk);
    clearValues();
    MainWindow.xaml
    <DataGrid
    Height="144"
    HorizontalAlignment="Left"
    Margin="79,447,0,0"
    Name="dataGrid1"
    VerticalAlignment="Top" CanUserAddRows="True"
    Width="399" Grid.RowSpan="2" IsReadOnly="False">
    <DataGrid.Columns>
    <DataGridTextColumn Header="NAME" Binding="{Binding NameTextField,Mode=TwoWay}" Width="Auto" IsReadOnly="False" />
    <DataGridTextColumn Header="ADDRESS" Binding="{Binding AddressTextField,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTextColumn Header="GENDER" Binding="{Binding GenderField,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTextColumn Header="COUNTRY" Binding="{Binding CountryField,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTextColumn Header="STATE" Binding="{Binding StateField,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTextColumn Header="PRODUCT" Binding="{Binding Product,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTemplateColumn Header="ACTION" MinWidth="140" IsReadOnly="False">
    <DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
    <ComboBox x:Name="actionddl" ItemsSource="{Binding ActionColl}"/>
    </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
    </DataGrid.Columns>
    </DataGrid>
    In the above "xaml" file i am using the attribute "Readonly="False"" but its not effected on my code still my datagrid is in readonly mode, i don't know why it happens. 
    And I am adding data to my datagrid through "Wpf controls (TextBox,CheckBox,ComboBox and etc...)"  while click on "save" button the data added to grid. adding to grid works properly but the entire row is in readonly mode. How can
    i solve my problem.  

  • Issue in cell format when exporting data to excel

    Hello there,
    I have an ABAP program that selects data from tables into an internal table and writes the data in CSV (excel) file.
    I have a very weird issue when writing the file: The data is written properly, though the dates in my data, which is written in yyyymmdd format, has different cell format in the csv file itself. I'll expain:
    Let's say I've written into CSV file a table with name and birthdate, and I have 2000 records. From record 1 to 1475, when I right-click on the date cells in those lines, and choose "cell format", I can see it's in "general" format. From line 1476 on, when I do that I see that the date cells are in format of "custom" with pattern 'yyyymmdd'.
    I want all the cells to be "general". How do I do that?
    Thanks in advance

    Hi Daniel,
    Try using these Function Module......................
    Before filling final internal table write those condition.................................
    Data:  gv_date   TYPE mch1-vfdat,
             gv_vdate(10) TYPE c.
    CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
           EXPORTING
             date_internal            = gv_date
           IMPORTING
             date_external            = gv_vdate
           EXCEPTIONS
             date_internal_is_invalid = 1
             OTHERS                   = 2.
         IF sy-subrc <> 0.
    * Implement suitable error handling here
         ENDIF.

  • Help needed to add an image to a datagrid cell in actionscript

    Morning all,
    I am still quite new to flex development and I have an application which uses xml to populate a datagrid. One of the row columns should display a small image but I don't know how to do that.
    Can anyone show me how to add an image to a datagrid cell in actionscript?
    I've added a sample of the code I have written already below. Any help would be much appreciated.
    Thanks in advance,
    Xander
    My XM
    <?xml version="1.0" encoding="UTF-8"?>
    <dataset>
    <modules>
    <module id="1">
    <icon>assets/sample_image1.png</icon>
    <key>core</key>
    <name>Core</name>
    <description>Description of module</description>
    <installed>Wednesday, 24th June 2009 @ 15:59 UK</installed>
    </module>
    <module id="2">
    <icon>assets/sample_image2.png</icon>
    <key>webproject</key>
    <name>Web Project</name>
    <description>Description of module</description>
    <installed>Wednesday, 24th June 2009 @ 17:32 UK</installed>
    </module>
    </modules>
    </dataset>
    My Actionscript
    private function dataSetHandler(event:Event):void {
        var ds:XML = new XML(event.target.data);
        var rows:XMLList = ds.elements('modules').elements('module') as XMLList;
        var columns:Array = new Array();
        for (var i:int=0; i<rows[0].elements().length(); i++) {
            var column:DataGridColumn = new DataGridColumn();
            var tag:String = rows.*[i].name();
            column.headerText = rows.*[i].name();
            column.dataField = rows.*[i].name();
            if (tag == 'icon') {
                var img:Image = new Image();
                img.id = "iconpath";
                img.width = 23;
                img.height = 20;
                img.source = rows.*[i].name();
               column.itemRenderer = img;   <-- this line shows as an error when I try to compile
            columns[i] = column;
        mydatagrid.columns = columns;
        mydatagrid.dataProvider = rows;

    you cant just set image object to itemrenderer, you need to use classfactory.
    http://livedocs.adobe.com/flex/3/html/help.html?content=cellrenderer_4.html

  • Currency cell format does not export to excel doc

    Hi
    i am using new numbers on my macbook also on new OSX mavrics
    i have a invoice template that i have used for a good few years
    it has a fair amount of formulas and cell formats running
    the company i contract to uses windows based (office) system so i save the spreadsheet as an exel compatible file to send to them no problems
    untill now
    when i export to excel in ether .xls or .xlsx and open the document ether in numbers or on a windows pc on office 2007 all of the currency related cells are changed to 5 digits eg   -£8295.00 instead of £25 and the cell format show custom
    if i higlight the cell and change to curency the entrys chnge to the correct value
    has any one witnessed this ?
    it also is the same saving an excel sheet as a mac format CSV file and open that in numbers
    please help

    I am having exactly the same problem. Need to send invoices for work. Desperate for someone to help with a solution!!! thanks Stuart

  • OLE2. How to set cell format to percentage

    hi,
    how can I set the cell format to percentage? I tried with
    ole2.set_property (cell, 'NumberFormat', '%');
    OLE2.set_property(cell, 'Formula', '=A1/B1');
    but this only print a '%' at the end of the cell. Really, the cell format is not percentage, and formula is not calculated.

    solved.
    ole2.set_property (cell, 'NumberFormat', '0,00%');

  • Hide row and cell by cell formatting

    Hello,
    I am new to both diadem and VBS and I am having difficulties in translating calculations between excel and diadem.  I know that diadem doesn't have the same cell by cell formatting that excel does but is there a way to either hide rows that do not meet a certain condition or a way to say use an equation of the form
      =IF(H5> 0,J5+M4,0), where H is the conditional column and M is the resultant column?
    Thank you

    Hello ccimac,
    You might want to look at the IIF function to help you solve that particular problem,
    Example:
    Call Calculate("Ch(""ResultNV"")=IIf( Ch(""Channel1"")>1,Ch(""Channel1""),NoValue)" )
    This will create a NEW data channel called ResultNV that checks (in this example) whether a channel called Channel1 is larger than 1 or not. If it is, the value will the the actual channel value, if the values are smaller than 1 the software will replace the values with a NoValue - which is DIAdem's way of saying that a "cell" contains invalid values.
    Does that work for your question? Feel free to ask if you have further questions,
         Otmar
    Otmar D. Foehner
    Business Development Manager
    DIAdem and Test Data Management
    National Instruments
    Austin, TX - USA
    "For an optimist the glass is half full, for a pessimist it's half empty, and for an engineer is twice bigger than necessary."

  • Excel cell formatting

    I have a programme that sorts through test results and picks out the rejects according to its "delta" value. I've noticed now that some rejects weren't picked up for some reason. As a fail safe I want to be able to highlight any cell whose value is above a certain limit in two columns.
    Any ideas?
    Solved!
    Go to Solution.
    Attachments:
    Matching Dual Devices.vi ‏35 KB

    Hello Kevin,
    Here is a Quick diagram that should help you get started on highlighting the data you want. It looks at the column "7" data and compares it to a requirement then changes the Cell formating to a green color if the equals is true. As you can probably guess the Flase case changes the cell color to red.
    I hope this helps.

  • How to change content of DataGrid cell on mouse over

    I am trying to change content of a datagrid cell when the mouse is over it. Changing the dataProvider does not provide immediate feedback because update is performed by renderer. I am trying to directly update content of a cell onMouseOver and restore it onMouseOut.
    I am thinking of leaving the column empty and insert content onMouseOver, cleanup onMouseOut. Alternative, may be I can populate the column and mask out all but the cell the mouse is over.
    Any suggestion on how this may be done?
    Thanks!

    I would override updateDisplayList, call isItemHighlighted and set the content of the cell accordingly
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui

  • Moive clip in dataGrid cell.

    I want to put a movie clip into datagrid cell
    and cell data will change the color of the movie clip.
    how could I do that?
    pls help

    I think, you can use cellRenderer.
    If you want add icon something like that means, you can use
    "setPropertiesAt"

  • Remove currency symbol from currency cell format?

    This might seem like an odd question but I only want my top row to have the currency symbol and the rest of the rows to simply have the number with no currency. I know I can switch the cell format to Numbers but then I lose the formatting of how negative numbers are displayed (quotation marks versus the negative symbol).
    So, is there any way to simply remove the currency symbol from the currency cell format?

    Hello
    As the special format for negatives is only meaningful for currencies you can't get if if you disable the currency format.
    There is an alternate way to highlight negatives but I don't know if you would be satisfied with it.
    Select the cells whose format must be number, not currency.
    Open the Inspector of Cells
    Check "Conditional Format"
    Click "Show Rules"
    Of course, you may select an other color.
    Yvan KOENIG (from FRANCE mardi 22 janvier 2008 14:51:11)

  • Combobox behavior inside a datagrid cell

    How do you control the width of a combobox that resides
    inside a datagrid cell? Merely setting cb.dropdownWidth = "some
    value" does not work.

    ok.. i got it. You can successfully modify
    dropdownWidth from withing your CellRenderer class using the 'open'
    event.

Maybe you are looking for

  • Firmware 1.0.04 WRT120N

    Hi guys, the latest firmware is not good. does anybody have a link to download the 1.0.04? build 02 thanks!!

  • Sender IDoc

    Hi All, I have aquick question on sender IDoc Scenarios. I have done by WE20 settings in Sender R3 System for a given IDoc. Also I have done the IDX1 setings in XI system. The configurations are also done in XI. So when I trigger thr IDoc from the R3

  • HT1222 when will siri be able to be used in spanish?

    when will siri be able to be used in spanish?

  • Why does DropBox take 1.2 gigs of space on my iPad?

    When I check the usage area of my Ipad, it shows DropBox using 1.2 gigs of space.  I thought any documents, pictures, etc I put there are actually stored on their servers, not my Ipad.  Am I doing something wrong?  Is the app itself 1.2 gigs (I can't

  • How to copy from one image to another

    Hi, I'm struggling with the most basic process in PSE 10. I have selected an area in a photograph - now I want to delete the rest of that photograph and add the selected area as a layer to another photograph. Having spent hours searching online, I'm