ListView hide column by easy way
ListView hide column by easy way
用简单方式隐藏ListView中的列
lvData.Columns[5].Width=0;
and
并且
lvData.ColumnWidthChanging += new ColumnWidthChangingEventHandler(lvMatchupList_ColumnWidthChanging);
void lvMatchupList_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
if (e.ColumnIndex == 5 && e.NewWidth > 0)
e.Cancel = true;
}
if no effects because
可能会没有效果,因为
In order to receive the ListView::ColumnWidthChanging, you need to enable full dragging of windows.
Here is how to enable full dragging of windows:
1. Go to Control Panel
2. Click on Display
3. On the "Display Properties" dialog go to "Appereance" tab
4. On the "Appearance" tab click on "Effects" button - this will open the "Effects" dialog.
5. On the "Effects" dialog see if the "Show windows contents while dragging" check box is checked. If the check box is not checked, then check it.
6. Close the "Effects" dialog and then the "Display Properties" dialog.
Now full dragging of windows should be enabled on your machine and the ListView should fire the ColumnWidthChanging event.
another way
另一种实现
lvData.ColumnWidthChanged += new ColumnWidthChangedEventHandler(lvMatchupList_ColumnWidthChanged);
void lvMatchupList_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
{
if (e.ColumnIndex == 5 && lvData.Columns[5].Width > 0)
lvData.Columns[5].Width = 0;
}