- Add a button to the form. Name the button as buttonHideColumn.
- Add a button to the form. Name the button as buttonShowColumn.
- Then add following code. Change the value of the variable freezeColumn and i to freeze the user specified column. Column index start from 1. These two variables freezeColumn and i must be the same.
int freezeColumn = 2; int i = 2; private void buttonHideColumn_Click(object sender, EventArgs e)// hide { if (i < listView1.Columns.Count) { if (i >= freezeColumn) { listView1.Columns[i].Width = 0; } i++; } Console.WriteLine("<<<" + i); } private void buttonShowColumn_Click(object sender, EventArgs e)// show { if (i > freezeColumn) { i--; listView1.Columns[i].Width = -2; } Console.WriteLine(">>>" + i); }
沒有留言:
張貼留言