在c#中,我有一个listview控件。我希望其中一列中的文本字段在开头而不是结尾处被截断。
即。我希望第2列中的文本字段为:
... NAME1
... NAME2
... NAME3
而不是
... filena
... filena
... filena
答案 0 :(得分:1)
尝试
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);
}
如果只是一个特定的列,您希望看到此行为,请说col index = 5然后尝试
private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
if (e.ColumnIndex == 5)
{
e.DrawText(TextFormatFlags.Right);
}
else
{
e.DrawText();
}
}