.NET的ListView,最大数量的字符,或最大列宽?可以覆盖/扩展? [英] .NET ListView, max number of characters, or maximum column width? Possible to override/expand?

查看:192
本文介绍了.NET的ListView,最大数量的字符,或最大列宽?可以覆盖/扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET ListView控件中,我显示堆栈跟踪。我用的ListView,因为我需要处理的字体/某些线条的颜色。

I have a .NET ListView control in which I display stack traces. I used the ListView since I needed to manipulate the font/colors of certain lines.

然而,似乎有一些关于列的宽度种类最多的,字符的任一所显示的号码,或者像素的数量的列可以是

However, it seems there is some kind of maximum regarding the width of the columns, either the number of characters displayed, or the number of pixels a column can be.

下面是一个简单的 LINQPad 的例子,显示了这个问题:

Here is a simple LINQPad example that shows the problem:

void Main()
{
    using (var fm = new Form())
    {
        ListView lv = new ListView();
        fm.Controls.Add(lv);
        lv.Dock = DockStyle.Fill;
        lv.View = View.Details;
        lv.Columns.Add("C", -1, HorizontalAlignment.Left);

        string line = new string('W', 258) + "x";
        lv.Items.Add(line);
        line = new string('W', 259) + "x";
        lv.Items.Add(line);

        lv.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent);
        lv.Columns[0].Width.Dump();

        fm.ShowDialog();
    }
}

截图:

正如你所看到的,含258 W公司+一个X线,显示了X,而包含一个额外的W上的下一行,不显示在x

As you can see, the line containing 258 W's + an X, shows the x, whereas the next line containing one additional W, does not show the x.

宽度计算的输出有表明列的当前宽度为2864像素。

The output of the width calculation there shows that the current width of the column is 2864 pixels.

现在的问题是这样的:有什么我可以在ListView调整,以解决此限制

The question is this: Is there anything I can tweak on the ListView to work around this limitation?

推荐答案

此行​​为被记录在的 MSDN页面的ListViewItem

This behaviour is documented in the MSDN pages for ListViewItem:

在ListViewItem的的文字不超过259个字符,否则会发生意外的行为。

The text of the ListViewItem should not exceed 259 characters or unexpected behavior could occur.

<一个href="http://bytes.com/topic/visual-basic-net/answers/364645-autosize-limits-listview-column-sizes">According以微软的一名员工:

为什么ListView项的文本长度被限制在259字符   因为该列表视图是设计类似对象的显示集合   文件,而不是用于通用控制。所以它类似​​于文件名   长度限制在Windows文件系统的MAX_PATH。

Why the length of the text of listview item is limited to 259 character is because that the listview is design for display collection of objects like files and not for general purpose control. So it is similar to the filename length limitation in the windows file system's MAX_PATH.

还有一个 Microsoft支持文章。该的ListViewItem 并存储的全文,它只是有时间限制的显示。

There is also a Microsoft Support article about this. The ListViewItem does store the full text, it is just the display that is limited in length.

然而,它似乎可能的,如果你犯了一个自定义的的ListView 显示完整的文本,并将其设置为的OwnerDraw

However, it does appear possible to display the full text if you make a custom ListView and set it to OwnerDraw:

public class MyListView : ListView
{
    public MyListView()
    {
        OwnerDraw = true;
        DrawItem += new DrawListViewItemEventHandler(MyListView_DrawItem);
    }

    private void MyListView_DrawItem(object sender, DrawListViewItemEventArgs e)
    {
        e.Graphics.DrawString(e.Item.Text, e.Item.Font, 
                                    new SolidBrush(e.Item.ForeColor), e.Bounds);
    }
}

这显示了每个的ListViewItem 的全文。在这样做的缺点是,你还需要自定义绘制其他可视状态,以及(如选中状态,焦点状态,等...),除非你能以某种方式将它们路由通过对原始图形code

This displays the full text of each ListViewItem. The disadvantage in doing this is that you will also need to custom draw the other visual states as well (e.g. selected state, focus state, etc...) unless you can somehow route them through to the original drawing code.

我不知道是否有任何其他的副作用这样做。

I have no idea if there are any other side effects to doing this.

这篇关于.NET的ListView,最大数量的字符,或最大列宽?可以覆盖/扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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