954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Scrollbar not available in listview

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.

kirtee2209
Light Poster
28 posts since Apr 2011
Reputation Points: 19
Solved Threads: 1
 

Can you post your listview code

syd919
Junior Poster in Training
67 posts since Aug 2009
Reputation Points: 10
Solved Threads: 7
 

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;
kirtee2209
Light Poster
28 posts since Apr 2011
Reputation Points: 19
Solved Threads: 1
 

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);
            }
        }
kirtee2209
Light Poster
28 posts since Apr 2011
Reputation Points: 19
Solved Threads: 1
 

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

syd919
Junior Poster in Training
67 posts since Aug 2009
Reputation Points: 10
Solved Threads: 7
 

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?

syd919
Junior Poster in Training
67 posts since Aug 2009
Reputation Points: 10
Solved Threads: 7
 

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

manojkumar2004
Newbie Poster
13 posts since Nov 2007
Reputation Points: 12
Solved Threads: 2
 

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.

kirtee2209
Light Poster
28 posts since Apr 2011
Reputation Points: 19
Solved Threads: 1
 

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

manojkumar2004
Newbie Poster
13 posts since Nov 2007
Reputation Points: 12
Solved Threads: 2
 

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

kirtee2209
Light Poster
28 posts since Apr 2011
Reputation Points: 19
Solved Threads: 1
 

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

kirtee2209
Light Poster
28 posts since Apr 2011
Reputation Points: 19
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: