Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Listview, remove junk column

I have a C# ListView in mode "details", which makes the headers visible. I have 2 columns only, and still there's always a third junk empty one.

Anyone familiar with how to hide that ? I'm supposed to hand in a professional application and that's the kind of stuff that I'll get killed for GUI-wise..

Thanks ;)

like image 233
BuZz Avatar asked Nov 18 '11 16:11

BuZz


1 Answers

That third one I believe is just the leftover space. You'll need to size the other columns to fit. See this posting: Adjust ListView columns to fit with WinForms

The key is the -2 on the last column:


[c#]
private void Form1_Load(object sender, System.EventArgs e)
{
    SizeLastColumn(lvSample);
}

private void listView1_Resize(object sender, System.EventArgs e)
{
    SizeLastColumn((ListView) sender);
}

private void SizeLastColumn(ListView lv)
{
    lv.Columns[lv.Columns.Count - 1].Width = -2;
}
like image 193
Adam Tuliper Avatar answered Oct 21 '22 06:10

Adam Tuliper