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.

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);
            }
        }

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.

This article has been dead for over six months. Start a new discussion instead.