Color formatting not applied to my XtraTreeList column in devexpress at time of preview

288 Views Asked by At

On clicking Print prieview:

private void PrintPreview_Click(object sender, EventArgs e)
{
    // Adding treeList Component and it's look and feel.
    PreviewPrintableComponent(treeList, treeList.LookAndFeel);
}

Code responsible for print preview:

void PreviewPrintableComponent(IPrintable component, UserLookAndFeel lookAndFeel)
{
    // Create a link that will print a control. 
    PrintableComponentLink link = new PrintableComponentLink()
    {
        PrintingSystemBase = new PrintingSystemBase(),
        Component = component,
        Landscape = true,
        PaperKind = PaperKind.A5,
        Margins = new Margins(20, 20, 20, 20)
    };

    // I believe somewhere here I need to do something about formatting in 
    // 'component' and 'lookAndFeel'. 


    // creating preview doc
    link.CreateDocument();

    // showing preview
    link.ShowRibbonPreview(lookAndFeel);
}

The code for formatting my TreeList. This code is run during compile time as it is event generated at design time:

private void TreeList_NodeCellStyle(object sender, GetCustomNodeCellStyleEventArgs e)
{
    // "Number" is name of column in which color formatting is applied
    if (e.Column.FieldName == "Number")
    {
        // Changing color to red for negative value.
        if (Convert.ToInt32(e.Node.GetValue(e.Column.AbsoluteIndex)) < 0)
        {
            e.Appearance.ForeColor = Color.Red;
        }
    }
}

My TreeList in FormMy TreeList at print preview

1

There are 1 best solutions below

0
On

Try setting the TreeListOptionsPrint.UsePrintStyles property to false in order to use the appearance you specified in the NodeCellStyle event.