This is a migrated thread and some comments may be shown as answers.
How to handle the width of customized items?
0 Answers 0 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
红耀 asked on 24 Aug 2018, 08:58 AM

I want to develop a WinForms application which is similar with Outlook. For the email list part, I use the custom item in the ListView to display the email information(From, Subject, Receive Time, Body Content). The ListView control is inside a split container(Dock Fill). So that, user can change the width of ListView. 

The problem is, when the subject or body content is very long, I don't want the item to auto size. I want the item hidden the text when overflow. When user changes the width of ListView via split container, the text can be shown more or less according to the width of ListView. It likes in the outlook, you can change the width of the email list, the body content and the subject can be automatically displayed to fit the width. How to implement this function by using ListView?

My custom item as below:

private class MailListVisualItem : SimpleListViewVisualItem
            private LightVisualElement element1;
            private LightVisualElement element2;
            private StackLayoutPanel layout;
            protected override void CreateChildElements()
                this.layout = new StackLayoutPanel();
                this.layout.EqualChildrenWidth = false;
                this.layout.Margin = new Padding(20, 0, 0, 0);
                this.element1 = new LightVisualElement();
                element1.TextAlignment = ContentAlignment.TopLeft;
                element1.Size = new Size(260, 0);
                element1.MinSize = new Size(260, 0);
                element1.NotifyParentOnMouseInput = true;
                element1.ShouldHandleMouseInput = false;
                this.element2 = new LightVisualElement();
                element2.TextAlignment = ContentAlignment.TopLeft;
                element2.Size = new Size(80, 0);
                element2.NotifyParentOnMouseInput = true;
                element2.ShouldHandleMouseInput = false;
            protected override void SynchronizeProperties()
                if (this.Data.GetType() != typeof(ListViewDataItemGroup))
                    this.Text = "";
                    var bodyText = this.Data["BodyText"] == null ? "" : this.Data["BodyText"].ToString().Replace(System.Environment.NewLine, " ");
                    this.element1.Text = "<html><span>" +
                        "<span style=\"font-size:12\">" + this.Data["From"] + "</span>" +
                        "<br><span style=\"color:#13224D;font-family:Segoe UI;font-size:10\">" + this.Data["Subject"] + "</span>" +
                        "<br><span style=\"color:#13224D;font-family:Segoe UI;font-size:10\">" + bodyText + "</span></span></html>";
                    this.element2.Text = "<html><span> </span>" +
                        "<br><span style =\"color:#13224D;font-family:Segoe UI;font-size:10\">" + this.Data["ReceivedTime"] + "</span></html>";
                    this.TextAlignment = ContentAlignment.TopLeft;
            protected override Type ThemeEffectiveType
                    return typeof(SimpleListViewVisualItem);

No answers yet. Maybe you can help?

Asked by
Top achievements
Rank 1
Share this question