C1Datagrid Change Backgroundcolor of a Column by condition during runtime

Posted by: christoph.schattka on 9 November 2022, 10:37 pm EST

    • Post Options:
    • Link

    Posted 9 November 2022, 10:37 pm EST

    Hello,

    I’m using an old componentone C1Datagrid for WPF Version 3.0.20093.100. During runtime the quantity of the displayed columns are dynamically. So I’m using a variable and if its true, I want to change the backgroundcolor of the specific column.

    Its not working but the Codesnippet should explain, what i want to do:



    For Each column In DG_Maschinenplanung.ActualColumns

                        Select Case CInt(txt_AnzahlWochen.Text)
    
                            Case 1
    
                                If column.Caption.Contains(CStr(int_WeekOfYear)) Then
    
                                    column.SetValue(BackgroundProperty, New SolidColorBrush(Colors.Blue))
    
                                End If   ...........................
    

    Could you pleas help me to make this function working?

    Thanks in advance and best regards

    Christoph

  • Posted 10 November 2022, 9:06 pm EST

    Hi,

    You are using a very old version. This is out of support. We suggest you to update to the latest 4.6.2 version.

    However, to achieve your requirement with C1DataGrid Version 3.0.20093.100. You can create your custom **ItemCellContentPresenter **and can ApplyTemplate as:(see code snippet)

       public class CustomeItemCellContentPresenter : ItemCellContentPresenter
        {
            public override void OnApplyTemplate()
            {
                base.OnApplyTemplate();
                if (this.Cell.Column.Caption == "Name")
                {
                    (this.Parent as Border).Background = Brushes.Red;
                }
            }
        }

    Please refer the attached sample for the same : DataGridDemo.zip

    Best Regards,

    Nitin

  • Posted 13 November 2022, 5:55 pm EST

    Dear Nitin,

    many thanks for your very fast support. Your solution works fine for me.

    Best Regards,

    Christoph

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels