# [.net] Always show the scrollbar:

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

## 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 on other sites
Does nobody know how to make the scrollbar shown when it's not needed?

##### Share on other sites
Umm, why not just make the grid a bit wider?

##### Share on other sites
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 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 widthts.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 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 on other sites
Quote:
 Original post by CodeReaverWell, 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?

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633761
• Total Posts
3013725
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!