Jump to content
  • Advertisement
Sign in to follow this  
CodeReaver

[.net] Always show the scrollbar:

This topic is 4325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using a DataGridView and I want it to show the vertical scrollbar even when it's not needed. Does anyone know how to do this? The scrollbars property allows them to be shown if they're needed but not otherwise, but when the vertical scrollbar is needed, it reduced the width of the datagrid to make room causing it to need to horizonal one too. However I'd prefer a constant width.

Share this post


Link to post
Share on other sites
Advertisement
Well, making the grid wider would cause part of the grid to be missed off causing it to need the horizontal scroll bar as well. I wanted to avoid having the layout change on it's own like that, just because it looks a bit neater.

Share this post


Link to post
Share on other sites
I use to have the same problem when i have a width for my datagrid and then the content is modified because of the scrollbars.

I don't know how to show scrollbars when they are not needed, so i define a constant width for my columns in my datagrid. This method is annoying because you have to do it by hand but it warrants you a constant width so scrollbars do not bother you.

I have tried the following with .NET Framework 1.1


//each time you change your datagrid datasource:
DataGridTableStyle ts=new DataGridTableStyle(true);
ts.MappingName="yourDataTableName";
yourDataGrid.TableStyles.Add(ts); //your tablestyle is bound to your grid

ts.GridColumnStyles["yourColumn1"].Width=165; //alters your column width
ts.GridColumnStyles["yourColumn2"].Width=65;



I used this code to keep the width of my columns each time my datagrid's datasource was updated and it was useful to avoid horizontal scrollbars by keeping my columns inside the visible area of my grid. You have to disable the user from modifying your columns' width and you have to calculate the width of your columns by hand but it works.

Share this post


Link to post
Share on other sites
This is for making the horizontal scrollbar show up. I want to make the vertical one always present instead and the horizontal one never show up if thewidth is a constant size. I've tried adding my own scrollbar outside the datagridview, but I can't seem to calculate the right number of positions for it. I use the number of rows and there's too many and if I subtract the number of rows that fit on the screen there's not enough.

EDIT: I was in a bit of a rush when I replied, so I misread what you'd wrote. However I want to avoid resizing as much as possible so what you said still wouldn't be appropriate for how I want the program to behave. I'm making a hex editor with an ascii pane to the side. So I want to keep the hex cells having 2 characters and the ascii having one and I don't want any resizing other than when the user has deliberatly decided to. The appearing and dissapearing vertical scrollbar would cause this.

I'm using a splitter control between the hex and ascii grids, so I suppose I could try altering the minimum size of the panes, but I'd prefer to get the scrollbar working.

[Edited by - CodeReaver on November 19, 2006 5:56:07 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by CodeReaver
Well, making the grid wider would cause part of the grid to be missed off causing it to need the horizontal scroll bar as well. I wanted to avoid having the layout change on it's own like that, just because it looks a bit neater.


Huh?!? [oh] Maybe I'm just stupid today, but I don't get what the problem would be in making the grid wider to accomodate the scrollbar. Do you have a screenshot to show what you mean by the above?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!