Datagridview vertical scrollbar

How do i force the Datagridview vertical scrollbar always to show ?

Thanks
LVL 18
vbturboAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

REA_ANDREWCommented:
You cannot, you would have to implement a Vertical Scroll Bar Control and link up the datagridview binding events so that it can correctly scroll it.

Andrew
0
vbturboAuthor Commented:
do you have a small sample code on how to do that ?

Jens
0
vbturboAuthor Commented:
i have about 30 rows in my grid (win app)
The height of the grid is set so that it displays 5 rows and the scrollbar property is set to vertical but it never shows
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

SanclerCommented:
Jens

Are you wanting the vscrollbar ALWAYS to show?  Or is your problem that it is not showing when there are sufficient records to make it necessary?

If it's the latter, and the .Scrollbars prperty is set to Vertical, then there's something odd going on.  Are you setting the .Scrollbars property at desgin time, or run time?  How do you set the height to show precisely 5 records.  At the moment, I've no ideas, and cannot reproduce the problem, but those look to me to be factors that might be relevant.  What happens if you change the .Scrllbars property to Both?

Roger

PS - off topic

As you're about, if you're not too busy, you might like to pop in here

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23133003.html

I think there's a database design problem needs sorting out first, but it looks like it might then move into pukka DataRelations ;-)
0
vbturboAuthor Commented:
Roger

Thanks for popping in - i've already looked at your link and its looking very interresting-;)

This is how i populate the grid ,selecting only the specific columns i need.
I did set the scrollbar property (in the grids properties) to vertical but it doesnt show when populating the grid this way....hmmm
and  there are more rows than the grid can show (due to the height of the grid)

i have set scrollbar property in design time and also tried to apply it in runtime also, but.....no luck.
I dont really care if it is going to be a some sort of permanent scrollbar solution i just need the scrollbar to
to show when there are more rows than that can viewed in the grid.


        'Kreditnota kopi sendt grid
        dgGrid.AutoGenerateColumns = False
        dgGrid.AutoSize = True
        dgGrid.Columns(0).DataPropertyName = ds.Tables(0).Columns("navn").ColumnName()
        dgGrid.Columns(1).DataPropertyName = ds.Tables(0).Columns("dato").ColumnName()
        Dim dvKreditNotaSendt As New DataView(ds.Tables(0))
        dvKreditNotaSendt.RowFilter = String.Format("status = '{0}'", "Kredit kopi sendt")
        dgGrid.DataSource = dvKreditNotaSendt

hope you got a clue-:)

Jens
0
REA_ANDREWCommented:
Hi,

Apologies I had a few goes at this, and when I said you cannot do this, I was clearly wrong.  Inffact if you did what i said and added a vertical scroll bar then the datagridview has 2 of them, this is inefficient.  What you need to do is create a dervived object which inherits from the DataGridView.  I am a C# man myself but I don't think it will be too hard to transpose this:

You may need to tweak sizing behaviour also, so if the data gridview resizes, adjust the scroll bar hight if it does not have any rows to scroll.

Cheers

Andrew
    public partial class CustomDataGridView : DataGridView
    {
        public CustomDataGridView()
        {
            InitializeComponent();
            this.VerticalScrollBar.Visible = true;
            this.VerticalScrollBar.VisibleChanged += new EventHandler(VerticalScrollBar_VisibleChanged);
            this.VerticalScrollBar.SetBounds(this.VerticalScrollBar.Location.X, this.VerticalScrollBar.Location.Y, this.VerticalScrollBar.Width, this.Height);
        }
 
        void VerticalScrollBar_VisibleChanged(object sender, EventArgs e)
        {
            this.VerticalScrollBar.Visible = true;
        }
 
    }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vbturboAuthor Commented:
Thanks Andrew

Ill give it a try tomorrow at work and then drop a post , Its becoming late in Denmark.

Jens
0
SanclerCommented:
Jens

This is the offending line

        dgGrid.AutoSize = True

I'm not sure what it's supposed to do.  So far as I can see from the docs: nothing.  But if you get rid of it, the vertical scrollbar should show when the number of records makes it appropriate.

Roger
0
vbturboAuthor Commented:
Thanks Roger , nothing escapes the haweyes from Wales (just did the trick as desired).

Andrew
i've tested your solution also (and it works just fine)

Well here comes the hard part (i'm not able to accept both solutions) which both of you deserve.

Jens
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.