自动调整列表框的列宽 [英] Automatically adapt listbox column width

查看:144
本文介绍了自动调整列表框的列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码以编程方式将数据库中的元素添加到多列列表框中:

I programmatically add elements from a database to a multicolumn listbox using this code :

Do While (Not rs.EOF) 

        ExistingSheetsListBox.AddItem
        ExistingSheetsListBox.List(i, 0) = rs.Fields(0)
        ExistingSheetsListBox.List(i, 1) = rs.Fields(1)
        ExistingSheetsListBox.List(i, 2) = rs.Fields(2)
        ExistingSheetsListBox.List(i, 3) = rs.Fields(3)
        ExistingSheetsListBox.List(i, 4) = rs.Fields(4)

        i = i + 1

        rs.MoveNext
Loop

在列表框中的插入工作正常,但是列宽并不总是适合插入其中的元素的长度,我想知道我该怎么做,以使每列的列宽都适合于文字插入其中.

The insertion in the listbox works fine, but the column width is not always adapted to the length of the elements inserted in it, I would like to know how I can do so that the column width of each column is adapted to the text inserted into it.

编辑:我使用了@Excel Developers提出的解决方案以及@HarveyFrench给出的代码.

EDIT : I used the solution proposed by @Excel Developers with the piece of code given by @HarveyFrench.

推荐答案

您可以使用ColumnWidths属性设置列的大小.

You can use the ColumnWidths property to set the size of the columns.

例如`ExistingSheetsListBox.ColumnWidths ="60; 60; 160; 160; 60"

eg `ExistingSheetsListBox.ColumnWidths = "60;60;160;160;60"

有关更多信息,请参见此处

For more info see here

无论如何,我还没有发现根据每一列中的数据自动设置宽度的方法,而且我很确定这种方法不存在.

I have not found anyway to automatically set the widths depending ont he data in each column, and I am pretty sure such a method does not exist.

这篇关于自动调整列表框的列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆