Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

have a column in c# listview truncated at the beginning instead of the end

Tags:

c#

listview

in c#, i have a listview control. i want the text fields in ONE of the columns to get truncated at the beginning instead of the end.

i.e. i want the text fields in column 2 to read:

...name1

...name2

...name3

instead of

filena...

filena...

filena...

like image 769
o17t H1H' S'k Avatar asked Dec 28 '25 22:12

o17t H1H' S'k


1 Answers

Try

    void Form1_Load(object sender, EventArgs e)
    {
        listView1.OwnerDraw = true;
        listView1.DrawColumnHeader +=listView1_DrawColumnHeader;
        listView1.DrawSubItem+=listView1_DrawSubItem;
    }


    private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
    {
        e.DrawText();
    }

    private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
    {
        e.DrawText(TextFormatFlags.Right);
    }

if it's just one specific column that you would like to see this behavior say col index = 5 then try

    private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
    {
        if (e.ColumnIndex == 5)
        {
            e.DrawText(TextFormatFlags.Right);
        }
        else
        {
            e.DrawText();
        }
    }
like image 192
Bala R Avatar answered Dec 30 '25 15:12

Bala R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!