C# ListView 列宽调整 刷新

本文介绍了如何在C#中实现ListView列宽的自动调整。提供了两种方法:一种是将列宽设置为列头文本长度(-2),另一种是设置为列中最长项的长度(-1)。需要注意的是,当使用-1时,必须在添加完所有项之后再设置列宽。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/***********************************************************************
 *                    C# ListView 列宽调整 刷新 
 * 说明:
 *     记录将C#中的ListView列宽设置为自动调整。
 *
 *                                   2016-7-5 深圳 南山平山村 曾剑锋
 **********************************************************************/

一、参考文章:
    1. C# ListView Column Width Auto
        http://stackoverflow.com/questions/1257500/c-sharp-listview-column-width-auto
    2. C# Clear all items in ListView
        http://stackoverflow.com/questions/435379/c-sharp-clear-all-items-in-listview

二、有效信息:
    You gave the answer: -2 will autosize the column to the length of the text in the column header, -1 will autosize to the longest item in the column. All according to MSDN. Note though that in the case of -1, you will need to set the column width after adding the item(s). So if you add a new item, you will also need to assign the width property of the column (or columns) that you want to autosize according to data in ListView control.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值