Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
899 views
in Technique[技术] by (71.8m points)

c# - How to wordWrap the text in a column using ObjectListView

For example I have a big sentence:

"I like to eat pie and have fun around the house all day long!" And I want it to appear like this:

"I like to eat pie and have fun around the house all day long!"

In this post: Multi-line list items on WinForms ListView control? Grammarian said that you only need to have WordWrap on but I cannot find that option.

Thanks for the help in advanced

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Each column has a WordWrap property. Set that to true and the text of that column will wrap.

Remember, the list must be OwnerDrawn for the wrapping to be visible.

EDIT: I looked again today, and you are quite right -- that property has gone! I have no idea where it has vanished to. I'm sure it used to be there :(

OLVColumn should have a property like this:

    [Category("Behavior - ObjectListView"),
     Description("Draw this column cell's word wrapped"),
     DefaultValue(false)]
    public bool WordWrap {
        get { return wordWrap; }
        set { 
            wordWrap = value;
            if (wordWrap) {
                this.Renderer = new BaseRenderer();
                ((BaseRenderer)this.Renderer).CanWrap = true;
                ((BaseRenderer)this.Renderer).UseGdiTextRendering = false;
            } else {
                this.Renderer = null;
            }
        }
    }
    private bool wordWrap;

Put that in, and you'll be able to word wrap your column's contents.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...