Listview AutoReziseColumns 不起作用 [英] Listview AutoReziseColumns not working

查看:25
本文介绍了Listview 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?

而且我已经测试了不止一个列表视图控件...

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

我是这样使用它的:

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

当我完成在列表视图上添加项目时,我会调用它.

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.

ColumnContent 调整为最长的单元格内容,如果 HeaderText 比内容长,它剪辑标题文本.使用包含 1 或 2 个数字/字符的列进行测试,但有一个像FooBar Counter of Foo"这样的长标题.

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 中必须包含项目才能使 ColumnContent 有意义
  • 尽管名称中有 Auto,但它不是永久性设置 - 一旦添加其他内容,布局可能不正确,因此您可能需要定期重置它.
  • 你总是可以按照你想要的方式布置它们并将 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)

可以使用 Width 属性和 -1(设置为内容)或 -2(大小为标题)的幻数来自动调整大小".这允许您仅将 AutoResize 逻辑应用于某些列或根据列使用不同的设置:

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 宽度属性.

One place this is very handy is when adding columns dynamically. Rather than guessing at the TextExtent, you can set the new column's width to something at least somewhat applicable to start with, then change it the first time content is added. Reference: MSDN ColumnHeader Width Property.

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

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