This is a migrated thread and some comments may be shown as answers.

Individual Listview Column and Cell Alingment

1 Answer 386 Views
ListView
This is a migrated thread and some comments may be shown as answers.
chris_techno25
Top achievements
Rank 1
chris_techno25 asked on 23 Jun 2013, 06:22 AM
Hi, is it possible to make different alignment formats to each column? Like first column is centered, second is right, and third is left, thanks :)

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 25 Jun 2013, 06:53 AM

Hello Chris, 

Thank you for writing.

It is  possible to make different alignment for each column. Here is  code sample how to do that:

private void radListView1_CellFormatting(object sender, ListViewCellFormattingEventArgs e)
{
    if ((e.CellElement).Data.HeaderText == "CustomerID")
    {
        if ((e.CellElement is DetailListViewDataCellElement))
        {
            e.CellElement.TextAlignment = ContentAlignment.TopRight;
        }
    }
    if ((e.CellElement).Data.HeaderText == "CompanyName")
    {
        if ((e.CellElement is DetailListViewDataCellElement))
        {
            e.CellElement.TextAlignment = ContentAlignment.MiddleCenter;
        }
    }
}

First I am handling the CellFormating event, then with the first if statement I am making sure it is thrown for a specific column. The second if statement checks the type of the element and if it is a cell, we can set its ContentAlingment property. If you also want to format the column heading you can omit the second if statement.

In the attached demo you can find the entire logic I use. 

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Mitko
Telerik
RadChart for WinForms is obsolete. Now what?
Tags
ListView
Asked by
chris_techno25
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or