Hi I have a listview in a C# windows form. I have created 2 columns and set their size by using the Columns Property. The Scrollbar property is set to true and listview has been set as Details.
The issue I am having is that when the listview is being populated programmatically, and if the data populated is greater than the columns' size, the horizontal scrollbar is not appearing.
Any help will be greatly appreciated.

Recommended Answers

All 10 Replies

Can you post your listview code

Well i have drag a listview from the toolbox into the form, and used the modified the properties by wizard.
Here are the code from the Form.Designer:

// 
            // lsvStatusesOut
            // 
            this.lsvStatusesOut.Alignment = System.Windows.Forms.ListViewAlignment.Left;
            this.lsvStatusesOut.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.lsvStatusesOut.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.colListHcCode2,
            this.colListHcDesc2});
            this.lsvStatusesOut.FullRowSelect = true;
            this.lsvStatusesOut.HideSelection = false;
            this.lsvStatusesOut.Location = new System.Drawing.Point(9, 43);
            this.lsvStatusesOut.Name = "lsvStatusesOut";
            this.lsvStatusesOut.Size = new System.Drawing.Size(352, 394);
            this.lsvStatusesOut.Sorting = System.Windows.Forms.SortOrder.Ascending;
            this.lsvStatusesOut.TabIndex = 23;
            this.lsvStatusesOut.UseCompatibleStateImageBehavior = false;
            this.lsvStatusesOut.View = System.Windows.Forms.View.Details;
            this.lsvStatusesOut.MouseClick += new System.Windows.Forms.MouseEventHandler(this.lsvStatusesOut_MouseClick);
            // 
            // colListHcCode2
            // 
            this.colListHcCode2.Text = "colListHcCode";
            this.colListHcCode2.Width = 70;
            // 
            // colListHcDesc2
            // 
            this.colListHcDesc2.Text = "colListHcDesc";
            this.colListHcDesc2.Width = 278;

Here is how I am populating the list view:

/// <summary>
        /// Populates the status list view.
        /// </summary>
        private void PopulateStatusListView()
        {
            for (int i = 0; i < initialStatusCodes.Length; i++)
            {
                string[] statusCodeAndDescription = new string[2];

                statusCodeAndDescription[0] = initialStatusCodes[i].CodeAndDesc;

                statusCodeAndDescription[1] = initialStatusCodes[i].Description;

                ListViewItem lvItem = new ListViewItem(statusCodeAndDescription);
                lsvStatusesOut.Items.Add(lvItem);
            }
        }

Try setting the dock property to fill and se what happens.

You can also try setting the alignment property to left, this way you will get a long row with multiple columns, Do you want one row with many columns?

is it possible for you to add the listview in a ScrollViewer? ... I have tried the same in wpf and it works fine

The listview is in a panel. The panel contains a label and 2 buttons. When I set the listview's dock property to fill, it overlaps the other controls in the panel.
The Alignment is already set to left. I want only 2 columns, and horizontal scrollbar to appear only if the data in the second column is greater than the size set.
I can't find ScrollViewer in Windows Form Application.

please try the autoscroll property ... make sure it is enabled ...

The scrollbar property is set to true but it's still not working.

Please help! I have not been able to resolve this issue yet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.