Nathan Van Dyken
Nathan Van Dyken

Reputation: 352

Show vertical scroll bar on disabled DataGridView

I have a DataGridView that is placed on a form that the user cannot directly interact with. The form must be disabled to achieve this effect and consequently my DataGridView is also disabled. This means that the scroll bar is greyed out and does not display the user's current position in the control. The user is able to scroll through the DataGridView with and when they are in another form, so it is important that they are able to tell how large the list is and where they are in it.

My question is this: how can I show the vertical scroll bar on a DataGridView that is disabled?

Note: Many people have solved this problem by enabling the DataGridView and setting the ReadOnly property to true. This will not work for me because the parent form must be disabled.

Upvotes: 2

Views: 3170

Answers (1)

Pavan Chandaka
Pavan Chandaka

Reputation: 12731

It is not possible to enable the scroll bars if the Grid is disabled.

In the below link look for the note: When a scrollable control is disabled, the scroll bars are also disabled. For example, a disabled multiline textbox is unable to scroll to display all the lines of text.

SRC: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.enabled(v=vs.110).aspx

But you can achieve your goal in a different way.

Try the below, and the explanation is in comments.

           //INSTEAD OF DISABLING FORM, DISABLE ALL THE CONTROLS IN THE FORM
            foreach (var pb in this.Controls.OfType<Control>())
            {
                pb.Enabled = false;
            }

            //NOW ENABLE THE DATAGRID VIEW
            this.dataGridView1.Enabled = true;

            //MAKE DATAGRID VIEW READ ONLY
            this.dataGridView1.ReadOnly = true;

Upvotes: 1

Related Questions