Enable scroll bar from disabled listview in C#

I'm getting confusion. I'm set :

this.listView1.Enabled = false;

when i make do that listview's scroll bars are disabled, too. I want to see all listviewitems in listview with scroll bars when listview disabled. Please give me some advices. Thanks.

Upvotes: 4

Views: 5901

Answers (4)

NicolasKittsteiner
NicolasKittsteiner

Reputation: 4370

Maybe if you put your listview inside a Panel you can enable scrolling by setting up ScrollBars="Auto" on the Panel control

Upvotes: 0

Sujay Ghosh
Sujay Ghosh

Reputation: 2868

You can't scroll a disabled control - but if you really need such a functionality, develop a user control.

Developing Custom Controls in C#

Hiding the scroll bar in CheckListbox

Writing your custom control step by step.

Upvotes: 1

Marco
Marco

Reputation: 57573

After a lot of comments, I'm assuming your listview, because of is updated often from many different threads, is flickering.
If so, one possible solution is to enable DoubleBuffering; this property anyway is protected so accessible only from descendant classes.
So you could:

  1. Add a new class to your project and paste the code shown below
  2. Compile
  3. Drop new control from the top of the toolbox onto your form, replacing the old one

This could solve your problem.

using System;
using System.Windows.Forms;

class BufferedListView : ListView 
{
    public BufferedListView() 
    {
        this.DoubleBuffered = true;
    }
}

The idea is taken from this post on SO.

Upvotes: 2

Alex
Alex

Reputation: 23300

you can't scroll a disabled control, since scrollbars are part of the control itself (and it's disabled, so...).

if you want to scroll but not allow user to select anything, you could do this

this.listBox1.SelectionMode = SelectionMode.None;

if you want to revert it, you can set it to SelectionMode.One for single, or one of the other options for multiple selection allowance.

another (imho overcomplicated) option is making a user drawn ListBox.

Upvotes: 2

Related Questions