Individual Listview Column and Cell Alingment

2 posts, 0 answers
  1. chris_techno25
    chris_techno25 avatar
    1 posts
    Member since:
    Nov 2012

    Posted 23 Jun 2013 Link to this post

    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 :)
  2. Dimitar
    Dimitar avatar
    1321 posts

    Posted 25 Jun 2013 Link to this post

    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.

    RadChart for WinForms is obsolete. Now what?
  3. DevCraft R3 2016 release webinar banner
Back to Top