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

Alternate Row Color

Sort Posts: Previous Next
  •  02-19-2009, 3:47 AM Post no. 18728

    Alternate Row Color

    How can i set Alternate Row color from Code behind...?

     

    the user will select the color which he wants from a color picker.

  •  02-19-2009, 8:40 AM Post no. 18730 in reply to 18728

    Re: Alternate Row Color

    Please refer to the following topic in the documentation: http://doc.xceedsoft.com/products/XceedWpfDataGrid/Alternating%20data%20row%20styles.html
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  02-19-2009, 9:00 AM Post no. 18733 in reply to 18730

    Re: Alternate Row Color

    That shows how to do it in XAML. I need to do it in Code Behind...

    This is how i have tried.... but i dont know how to get  DataGridVirtualizingPanel.ItemIndexProperty..

     

                        IndexToOddConverter rowIndexConverter = new IndexToOddConverter();

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

                        Binding binding = new Binding();
                        binding.RelativeSource = new RelativeSource(RelativeSourceMode.Self);
                        object obj = GetValue(DataGridVirtualizingPanel.ItemIndexProperty);
                        binding.Path = new PropertyPath(obj);
                        binding.Converter = rowIndexConverter;
                        styleDataTrigger.Value = true;

                        styleDataTrigger.Binding = binding;
                        styleDataTrigger.Value = dgGrid.CurrentColumn.FieldName;

                        SolidColorBrush brush = new SolidColorBrush(cpd.SelectedColor);
                        brush.Opacity = cpd.Opacity;
                        Setter setter = new Setter(Xceed.Wpf.DataGrid.DataRow.BackgroundProperty, brush);
                        style.Setters.Add(setter);
                        List<string> lstProperties = new List<string>();
                        lstProperties.Add("Background");

                        this.dgGrid.Resources[typeof(Xceed.Wpf.DataGrid.DataRow)] = style;

  •  02-19-2009, 9:12 AM Post no. 18734 in reply to 18733

    Re: Alternate Row Color

    The DataGridVirtualizingPanel.ItemIndex property is an attached property and can be accessed as such. For more information on attached properties, please refer to the MSDN documentation: http://msdn.microsoft.com/en-us/library/ms749011.aspx
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  03-24-2009, 11:48 PM Post no. 19594 in reply to 18734

    Re: Alternate Row Color

    hi i writhe the foloowing cocde for changing row color based on my orderis field value but datatrigger 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");

    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);

    this.dataGridControl.Resources[typeof(Xceed.Wpf.DataGrid.DataRow)] = style;

  •  03-25-2009, 9:15 AM Post no. 19609 in reply to 19594

    Re: Alternate Row Color

    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:24 PM Post no. 19656 in reply to 19594

    Re: Alternate Row Color

    Hi Pankaj,

     I replied to your question in your other thread here : http://xceed.com/CS/forums/thread/19595.aspx


    Diane Lafontaine
    Technical Support / Technical Support Team Lead
    Xceed Software Inc.
  •  07-02-2009, 7:08 AM Post no. 22208 in reply to 19656

    Re: Alternate Row Color

    DataGridVirtualizingPanel.GetItemIndex(DataGridVirtualizingPanel.ItemIndexProperty) I am trying this but it is giving as it is asking for DependencyObject not DependencyProperty.
  •  07-03-2009, 8:03 AM Post no. 22250 in reply to 22208

    Re: Alternate Row Color

    anyone????
  •  07-03-2009, 8:09 AM Post no. 22251 in reply to 22250

    Re: Alternate Row Color

    You need to pass the container (Xceed.Wpf.DataGrid.DataRow) to the GetItemIndex and not its own dependency property. You can use the grid's GetContainerFromItem method to get the container from a data item.
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-03-2009, 8:38 AM Post no. 22252 in reply to 22251

    Re: Alternate Row Color

    This is the code i am using....

     

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

                    Binding binding = new Binding();               
                    //binding.Path = new PropertyPath(DataGridVirtualizingPanel.ItemIndexProperty);
                    object obj = DataGridVirtualizingPanel.GetItemIndex(dgGrid.GetContainerFromItem(dgGrid.SelectedItem as Xceed.Wpf.DataGrid.DataRow));
                    binding.Path = new PropertyPath(obj);
                    binding.Converter = new IndexToOddConverter();
                    binding.RelativeSource = RelativeSource.Self;               

                    styleDataTrigger.Binding = binding;
                    styleDataTrigger.Value = true;
                   
                    BrushConverter bConv = new BrushConverter();
                    SolidColorBrush brush = (SolidColorBrush)bConv.ConvertFromString(color); //new SolidColorBrush();
                    brush.Opacity = ToolWindow.CDouble(opacity);
                    Setter setter = new Setter(Xceed.Wpf.DataGrid.DataRow.BackgroundProperty, brush);
                    style.Setters.Add(setter);
                    List<string> lstProperties = new List<string>();
                    lstProperties.Add("Background");
                   
                    style.Triggers.Add(styleDataTrigger);
                    this.dgGrid.Resources[typeof(Xceed.Wpf.DataGrid.DataRow)] = style;

     if i m using binding.Path = new PropertyPath(DataGridVirtualizingPanel.ItemIndexProperty);

    It colors entire grid not the alternate row....

  •  07-03-2009, 11:38 AM Post no. 22254 in reply to 22252

    Re: Alternate Row Color

    Are you certain the "obj" is not null? You are casting the SelectedItem as an Xceed.Wpf.DataGrid.DataRow when in fact it represents the underlying data item. The result of the GetContainerFromItem should be cast as a DataRow.

    Is there a reason why you are doing this in code rather than the suggested XAML?


    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-06-2009, 12:50 AM Post no. 22270 in reply to 22254

    Re: Alternate Row Color

    I am building a wrapper for the Xceed grid. I have given a tool bar for the grid. The user will have various options one of them is to change alternate row color. On clicking the alternate row color option, The user will get a color picker. He can choose the color and that color will be applied to the grid.

     This is what i am trying to do. But in the solution suggested by you, i have to use GetContainerFromItem but there will be not a single row selected in my case. thats why i m confused what to do and how to get ItemIndex property.

  •  07-08-2009, 12:48 AM Post no. 22352 in reply to 22270

    Re: Alternate Row Color

    Kindly reply. I am stuck and i need this functionality to be finished asap.... Sad
  •  07-08-2009, 10:33 AM Post no. 22369 in reply to 22352

    Re: Alternate Row Color

    What you could try is bind the Color property of the SolidColorBrush you are using as the alternate row color to a dependency property defined on the main window:

     <Style TargetType="{x:Type xcdg:DataRow}">

      <Style.Triggers>

          <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, 

                             Path=(xcdg:DataGridVirtualizingPanel.ItemIndex), 

                             Converter={StaticResource rowIndexConverter}}"

                       Value="True">

              <Setter Property="Background">

                  <Setter.Value>

                      <SolidColorBrush Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:Window1}}, Path=Color}"

                                       Opacity="0.1" />

                  </Setter.Value>

              </Setter>

          </DataTrigger>

      </Style.Triggers>

    </Style>

     

    Then, via the menu or button, change the value of the dependency property, which should automatically change the alternate row color.


    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.