ListView动态修改列宽
来源:互联网 发布:原创文章是什么算法 编辑:程序博客网 时间:2024/04/29 20:19
在DataGridView中有autocolumnmode来动态改变现实Column的列宽,在ListView中是没有这个属性的,可以通过ListView.SizeChanged 事件去修改列宽,实现相同的效果
代码如下
private bool Resizing = false; private void ListView_SizeChanged(object sender, EventArgs e){ // Don't allow overlapping of SizeChanged calls if (!Resizing) { // Set the resizing flag Resizing = true; ListView listView = sender as ListView; if (listView != null) { float totalColumnWidth = 0; // Get the sum of all column tags for (int i = 0; i < listView.Columns.Count; i++) totalColumnWidth += Convert.ToInt32(listView.Columns[i].Tag); // Calculate the percentage of space each column should // occupy in reference to the other columns and then set the // width of the column to that percentage of the visible space. for (int i = 0; i < listView.Columns.Count; i++) { float colPercentage = (Convert.ToInt32(listView.Columns[i].Tag) / totalColumnWidth); listView.Columns[i].Width = (int)(colPercentage * listView.ClientRectangle.Width); } } } // Clear the resizing flag Resizing = false;}
参考链接:
C#: ListView – Dynamically Sizing Columns to Fill Whole Control
http://nickstips.wordpress.com/2010/11/10/c-listview-dynamically-sizing-columns-to-fill-whole-control/
——————————————————————————————————————————————————————————————————
欢迎大神光临菜鸟博客,希望能得到各位大神在编码方面的指引,同时欢迎与我一样刚进入编程世界的朋友一起讨论学习!相信前进的道路上,有你们,编程世界会更加精彩!
0 0
- ListView动态修改列宽
- ListView-修改标题列
- ListView修改列
- 动态修改ListView文字大小
- 动态修改ListView文字大小
- 动态修改ListView
- 动态修改listview
- ListView 动态增加列标题
- 动态列数据修改专用!
- c# datagridview动态修改列
- MYSQL动态修改列长度
- listView+Combox动态修改字段
- ListView列宽自适应
- listview列宽调整
- ListView 列添加动态加载图片
- 【WPF】动态绑定listview的列内容
- XtraGrid控件,实现在界面中动态修改列显示,列名列宽
- 如何动态修改dddw列的宽度
- Liblinear的安装使用的问题
- cin.get( ) VS cin.getline( )
- [OpenGL ES 03]3D变换:模型,视图,投影与Viewport
- 第十七周项目四日期结构体
- 九度OJ 1041 Simple Sorting (排序,STL)
- ListView动态修改列宽
- VS2010编译遇到的问题
- Majority Element
- 【纯代码】TableView简单配置
- 关于我的开源项目RedisFile讲解 一
- 打开别人的android时报错缺少android环境的解决办法
- iOS AES 与SHA256加密字符串
- Solr的一些查询参数
- 总结:自动生成网页截图(Screenshot)方法