不工作列表视图AutoReziseColumns [英] Listview AutoReziseColumns not working

查看:263
本文介绍了不工作列表视图AutoReziseColumns的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
Listview1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)

我有一个问题,因为这两种线分别产生相同的结果,这是在调整两者ColumnContent和HeaderSize同时

I'm having an issue since both of these lines separately produce the same result, which is resizing both the ColumnContent and the HeaderSize simultaneously.

我已经搜查,并拿出没有回答这一点,我只需要在HeaderSize调整大小,但上面的例子似乎不能正常工作......还是我失去了一些东西?

I've searched and come up with no answer for this, i only need to resize by the HeaderSize but with the above example it seems not to be working correctly... or am i missing something?

我已经与多个ListView控件测试...

And i've tested with more than one listview control...

编辑:我使用的是这样的:

I'm using it like this:

  Private Sub UserListResize()
    If Me.UserList.InvokeRequired Then
        Me.UserList.Invoke(Sub() UserListResize())
    Else
        UserList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
    End If
End Sub

当我与ListView控件添加项目完成后我打电话这一点。

I'm calling this when i'm finished with adding items on the listview.

推荐答案

他们不这样做了同样的事情,但有时很难区分它们。

They dont do the exactly the same thing, but it is sometimes hard to tell them apart.

HeaderSize 调整大小,每列 HeaderText.Length 最长的单元格内容的更大,因此从来没有剪辑的标题文字。

HeaderSize resizes each column to the greater of HeaderText.Length or longest cell content, thereby never clipping the header text.

Col​​umnContent 调整为其中的最长的单元格内容将如果的HeaderText较长则内容片段标题文本。用含有1或2个数字/字符的一列,但长头像富的FooBar的计数器进行测试。

ColumnContent resizes to longest cell content which will clip header text if the HeaderText is longer then the content. Test this with a column containing 1 or 2 digits/characters, but a long header like "FooBar Counter of Foo".

无论是模式将剪辑列文虽然,这意味着当你与经济标题文本,它可以像他们做同样的事情。其他的事情要考虑:

Neither mode will clip column text though, which means when you are economic with header text, it can look like they do the same thing. Other things to consider:


  • 的LV必须在其物品 Col​​umnContent 有意义

  • 自动的名字Inspite,它不是一个永久设置 - 只要你添加别的东西的布局可能不正确,所以你可能要重新设置定期。

  • 您随时可以布置它们要如何设置和 AllowColumnResize 为False

  • 您设置 AutoResizeColumn 在每列的基础上(注意是单数)

  • The LV must have items in it for ColumnContent to be meaningful
  • Inspite of Auto in the name, it is not a persistent setting - as soon as you add something else the layout may be incorrect, so you may have to reset it periodically.
  • You can always lay them out how you want and set AllowColumnResize to False
  • You set AutoResizeColumn on a per column basis (note it is singular)

各列的宽度可以自动大小的使用宽度属性和-1的幻数(设置为内容)或-2(大小标题)。这可以让你只自动调整逻辑只适用于某些列或使用取决于列不同的设置:

Individual column widths can be "auto sized" using the Width Property and the Magic Numbers of -1 (set to content) or -2 (size to Header). This allows you to only apply the AutoResize logic to only some columns or use a different setting depending on the column:

 For n As Integer = 0 To myLV.Columns.Count -1 Step 2    ' just do every other
     myLV.Columns.Width = -2        ' -2 =  size to column header text
                                    ' -1 = size to longest content
 Next n

一个地方,这是非常方便的动态添加列时。而不是在TextExtent猜测,你可以设置新的列宽的东西至少在某种程度上适用下手,然后改变它被添加在第一时间的内容。参考: MSDN的columnHeader Width属性的。

这篇关于不工作列表视图AutoReziseColumns的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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