ListView hide column by easy way 用简单方式隐藏ListView中的列

Post date: 2012/4/5 上午 03:58:38

用简单方式隐藏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;

}

复制代码