Text Align based on row data

Developer
May 12, 2012 at 7:00 AM

Hi,

Thank you for this great reporting tool.

Is it possible to set TextAlignment for each cell based on it's value? for example when binding a list of numbers to table, Odd numbers TextAlignment set to Left and Even numbers TextAlignment set to Right.

 

Thanks in advance.

Developer
May 13, 2012 at 10:08 PM

OK

I found a nasty solution for this by using ReportDocument.DataRowBound event.

here is a sample:

private void reportDocument_DataRowBound(object sender, DataRowBoundEventArgs e)
{
            int titleCellIndex = 1;
            var titleCell = e.TableRow.Cells[titleCellIndex];
            var level = _codeService.GetCodingLevel(code);

            if (level == CodingLevel.Common)
            {
                titleCell.FontSize += 2.0;
                titleCell.FontWeight = FontWeights.Bold;

                if (_creditor != 0)
                {
                    titleCell.TextAlignment = TextAlignment.Right;
                }
                if (_debtor != 0)
                {
                    titleCell.TextAlignment = TextAlignment.Left;
                }
            }
}

I will go to hell for this dirty code!!!

May 14, 2012 at 9:25 AM

Jalax, if it works then i think you should skip hell and go straight to heaven!