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

problem in BackgroundColor of datarow c# code

Sort Posts: Previous Next
  •  03-25-2009, 1:56 AM Post no. 19595

    problem in BackgroundColor of datarow c# code

    Hi i have written the below code which is having orders as a datatable with an orderid column and i want to change the color of all rows which have orderid= 10249 but this code is not working plz help

    Style style = new Style(typeof(Xceed.Wpf.DataGrid.DataRow ));

    DataTrigger styleDataTrigger = new DataTrigger();

     

    System.Windows.Data.Binding binding = new System.Windows.Data.Binding();

    binding.Path = new PropertyPath("OrderID");

    binding.Source = Orders;

    styleDataTrigger.Binding = binding;

     

    styleDataTrigger.Value = "10249";

    style.Triggers.Add(styleDataTrigger);

     

     

    Setter setter = new Setter(Xceed.Wpf.DataGrid.DataRow.BackgroundProperty, Brushes.Yellow );

    style.Setters.Add(setter);

  •  03-25-2009, 9:43 AM Post no. 19617 in reply to 19595

    Re: problem in BackgroundColor of datarow c# code

    What is not working? Do you have any errors in the output window?
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  03-25-2009, 5:11 PM Post no. 19653 in reply to 19595

    Re: problem in BackgroundColor of datarow c# code

    Hi Pankaj,

    When using a Trigger (or DataTrigger) in your Style, the Setter must be set on the Trigger and not on the Style.

    For example :

      Style style = new Style(typeof(Xceed.Wpf.DataGrid.DataRow ));
      DataTrigger styleDataTrigger = new DataTrigger();

      System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
      binding.Path = new PropertyPath("OrderID");
      binding.Source = Orders;

      styleDataTrigger.Binding = binding;
      styleDataTrigger.Value = "10249";

      Setter setter = new Setter(Xceed.Wpf.DataGrid.DataRow.BackgroundProperty, Brushes.Yellow );
      styleDataTrigger.Setters.Add(setter);

      Style.Triggers.Add(styleDataTrigger);


    Diane Lafontaine
    Technical Support / Technical Support Team Lead
    Xceed Software Inc.
  •  03-30-2009, 4:26 AM Post no. 19719 in reply to 19617

    Re: problem in BackgroundColor of datarow c# code

    Hi

    there is no error coming but i cannnot see the desired background color changed

  •  03-30-2009, 4:27 AM Post no. 19720 in reply to 19653

    Re: problem in BackgroundColor of datarow c# code

    hi

    i have done this but then too i am not able to see the desired result of background color change as per my trigger

  •  07-29-2009, 12:06 PM Post no. 23002 in reply to 19720

    Re: problem in BackgroundColor of datarow c# code

    It would be great if the Xceed team could close all these very valuable questions. We are all facing the same issues, so please answer with valid fixes.
  •  07-29-2009, 12:13 PM Post no. 23003 in reply to 23002

    Re: problem in BackgroundColor of datarow c# code

    What is not working with the solution provided by Diane? Are there any errors in the output window?
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  08-25-2009, 11:34 AM Post no. 23511 in reply to 23003

    Re: problem in BackgroundColor of datarow c# code

    I have tried Diane's method as well, but it doesn't seem to work and there are no errors shown in the Output window.  I have put together a sample application demonstrating this method (as well as some others) at this post: http://xceed.com/CS/forums/23510/ShowThread.aspx#23510

    It is invoked by pressing the 'Method 3' button.

    Any assistance with this would be greatly appreciated.

    Many thanks,

    Jason


    Associate, .NET Development
    Morgan Stanley, UK
  •  08-31-2009, 4:42 PM Post no. 23614 in reply to 23511

    Re: problem in BackgroundColor of datarow c# code

    Hi Jason,

    see if the following is make scense.

    Style style = new Style(typeof(Xceed.Wpf.DataGrid.DataRow));

    DataTrigger styleDataTrigger = new DataTrigger();

    System.Windows.Data.Binding binding = new System.Windows.Data.Binding();

    binding.Path = new PropertyPath("MyProp1");

    binding.Source = MyDataList;

    styleDataTrigger.Binding = binding;

    styleDataTrigger.Value = "Val5";

    Setter setter = new Setter(Xceed.Wpf.DataGrid.DataRow.BackgroundProperty, Brushes.Yellow);

    styleDataTrigger.Setters.Add(setter);

    style.Setters.Add(setter);

    style.Triggers.Add(styleDataTrigger);

    dgcMyData.ItemContainerStyle = style;

    ((DataGridCollectionView)this.dgcMyData.ItemsSource).Refresh();

  •  09-22-2009, 3:45 PM Post no. 24095 in reply to 23614

    Re: problem in BackgroundColor of datarow c# code

    Hi Suresh,

    I tried this, but all the cells in my DataGrid just appeared yellow.  The Style DataTrigger doesn't seem to have an effect.  However, I have updated the example including this method (Method3) in the following thread, and it looks like I might be getting further doing it via XAML rather than programmatically:


    Associate, .NET Development
    Morgan Stanley, UK
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.