473,848 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView - Vertical ScrollBar Help Needed

Tom
First, I posted a similar request for help in another group and now
don't find the posting. Problem with my newsreader perhaps ... but
apologies if this appears as a cross posting.

My code is inconsistent in the detection of a vertical scrollbar. This
involves situations when less than the client area is needed to hold
the small amount of data. The inconsistency is when adjusting the
panel size within or just below the bottom row. Sometimes the code
adjusts the splitter of the panel as if a vertical scrollbar was
present ... when it is not. This results in seeing a portion of the
panel outside the DataGridView where the scrollbar resides when it is
needed.

I use the following code to detect if a vertical scrollbar is present:

grid2.AutoResiz eColumns();
grid2.AutoResiz eRows();

int i, sum = 0;
for(i = 0; i < grid2.ColumnCou nt; ++i)
{
sum + grid2.Columns[i].Width;
}

if(grid2.Prefer redSize.Height split2.Panel2.C lientSize.Heigh t)
{
// Adjust splitter to fit columns WITH a vertical scrollbar present
split2.Splitter Distance =
Math.Max(100, ActiveForm.Widt h - sum + Split2.Splitter Width - 35);
}
else
{
// Adjust to fit columns WITHOUT a vertical scrollbar present.
split2.Splitter Distance =
Math.Max(100, ActiveForm.Widt h - sum + Split2.Splitter Width - 19);
}

I wish I knew how to directly determine if the vertical scrollbar is
present without using the PreferredSize.H eight ClientSize.Heig ht
comparison. Rather than summing the column widths and using the sum
value, I've also used Preferred.Width ... but see the same effect.

I've printed out the Preferred.Width and ClientSize.Heig ht and these
are updating correctly. The problem seems internal of the DataGridView
control itself in that it is obviously using a different determination
for the displaying of the scrollbar. I'm almost convinced this is
actually a flaw of the control that needs to be fixed ... but usually
when I feel this way I find it is because I have done something wrong
and the controls end up being robust.

Thanks for any help sent my way. :)

-- Tom
Jan 30 '08 #1
1 13751
if(dgv.DisplayR ectangle.Height < dgv.ClientRecta ngle.Height)
//TODO: add code when scrollbar is showing
else
//TODO: add code when scrollbar is not showing

You will need to check the .RowHeight in the .RowTemplate and divide the
..DisplayRectan gle by that to see how many rows will display, and if you have
more rows than that, the vertical scrollbar will show.
--
Misbah Arefin

"Tom" wrote:
First, I posted a similar request for help in another group and now
don't find the posting. Problem with my newsreader perhaps ... but
apologies if this appears as a cross posting.

My code is inconsistent in the detection of a vertical scrollbar. This
involves situations when less than the client area is needed to hold
the small amount of data. The inconsistency is when adjusting the
panel size within or just below the bottom row. Sometimes the code
adjusts the splitter of the panel as if a vertical scrollbar was
present ... when it is not. This results in seeing a portion of the
panel outside the DataGridView where the scrollbar resides when it is
needed.

I use the following code to detect if a vertical scrollbar is present:

grid2.AutoResiz eColumns();
grid2.AutoResiz eRows();

int i, sum = 0;
for(i = 0; i < grid2.ColumnCou nt; ++i)
{
sum + grid2.Columns[i].Width;
}

if(grid2.Prefer redSize.Height split2.Panel2.C lientSize.Heigh t)
{
// Adjust splitter to fit columns WITH a vertical scrollbar present
split2.Splitter Distance =
Math.Max(100, ActiveForm.Widt h - sum + Split2.Splitter Width - 35);
}
else
{
// Adjust to fit columns WITHOUT a vertical scrollbar present.
split2.Splitter Distance =
Math.Max(100, ActiveForm.Widt h - sum + Split2.Splitter Width - 19);
}

I wish I knew how to directly determine if the vertical scrollbar is
present without using the PreferredSize.H eight ClientSize.Heig ht
comparison. Rather than summing the column widths and using the sum
value, I've also used Preferred.Width ... but see the same effect.

I've printed out the Preferred.Width and ClientSize.Heig ht and these
are updating correctly. The problem seems internal of the DataGridView
control itself in that it is obviously using a different determination
for the displaying of the scrollbar. I'm almost convinced this is
actually a flaw of the control that needs to be fixed ... but usually
when I feel this way I find it is because I have done something wrong
and the controls end up being robust.

Thanks for any help sent my way. :)

-- Tom
Feb 3 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11025
by: Don Schneider | last post by:
I tried to setup a frameset which consists of 4 different subframes. Each of these subframes should fetch a different web page from the internet and display it completely (!). BUT: the vertical size should be undefined. Depending on the retrieved (lets say 2nd) webpage the frame should take as much space as it needs to display the whole sub web page without vertical scrollbar. If I implement it like below a vertical scrollbar for each of...
2
6512
by: Per Jessen | last post by:
This is a javascript question, possibly somewhat inappropriate for this group, but here we go: (please redirect me to the right place to ask). In Microsoft Internet Explorer (5 and up) using Javascript how do I detect whether an IFRAME is displayed with or without a vertical scrollbar? The initial height of an IFRAME is fixed, so depending on the content, the browser will render it with a scrollbar or not. In Netscape et al. this is...
4
13569
by: Rob T. | last post by:
I am using a div tag to make an element that contains some text. I have specified overflow: auto; in my stylesheet. If I use font-size/line-height to specify the font information I get a vertical scrollbar in firefox/netscape (not IE) , even though the text I have in the element does not exceed the bounds. The simple example below casues this behaviour. How do I fix this? <div style="overflow:auto; height:100px; width:100px;...
3
9908
by: buht | last post by:
Hello Everyone, Fairly new to c# here and have a question regarding scrollbars, particularly a vertical scrollbar. It looks like my options are restricted for the textbox scrollbars being that I can enable vertical or horizontal scrollbars for the textbox and their wrapping but thats it for modifications of the scrollbar.
0
2392
by: Gene Hubert | last post by:
I've got two treeviews side by side on a panel on a form. They each have about 20 nodes in them. The treeview on the right has a vertical scrollbar. The treeview on the left needs a vertical scrollbar but does not have one. I have tried TreeView.Scrollable = True and calling ExpandAll() before the tree view is displayed with no success. I have checked the value of .Scrollable at runtime and it is true. If I select a node in the...
1
12644
by: steve | last post by:
Hi All Is there anyway to change the width of datagridview controls vertical scrollbar I have an Application where the datagridview fills most of the screen and it is hard to grab the scrollbar with a Touch screen Regards
4
2684
by: ShaneO | last post by:
In a Windows Form I have a RichTextBox with Multiline = True and ScrollBars = Vertical. As expected, when Text is loaded into the RTB the Vertical ScrollBar will appear if needed. Does anyone know of a way (in Code) to determine if the Vertical ScrollBar is visible or not? (VB 2005) This question has been asked a couple of times over several months but so far nobody has responded.
0
3586
by: jazeelkm | last post by:
hi, i am a beginer in the world of C# 1. I want to hide the vertical scrollbar of a listbox . In properties i can hide the horizontal scrollbar , but there s no option for vertical scroll bar.how can i hide this? 2. I also want to call the event of vertical scrollbar on a button
1
5660
by: platoon1sc | last post by:
Hi guys.I have a problem with Internet Explorer in my web-application. I have a vertical scrollbar into my jsps but firefox show the vertical srollbar, but IE doesn't. IE show a blank space where vertical scrollbat must be there. Where the FF show de scrollbar, IE show blank space, but doesn't show the scroll. My css for the scrool is: #content { clear: left; height:100%; width:100%; margin:5px; }
0
9893
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11001
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10664
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10722
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9500
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7894
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5919
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.