473,289 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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.AutoResizeColumns();
grid2.AutoResizeRows();

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

if(grid2.PreferredSize.Height split2.Panel2.ClientSize.Height)
{
// Adjust splitter to fit columns WITH a vertical scrollbar present
split2.SplitterDistance =
Math.Max(100, ActiveForm.Width - sum + Split2.SplitterWidth - 35);
}
else
{
// Adjust to fit columns WITHOUT a vertical scrollbar present.
split2.SplitterDistance =
Math.Max(100, ActiveForm.Width - sum + Split2.SplitterWidth - 19);
}

I wish I knew how to directly determine if the vertical scrollbar is
present without using the PreferredSize.Height ClientSize.Height
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.Height 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 13688
if(dgv.DisplayRectangle.Height < dgv.ClientRectangle.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
..DisplayRectangle 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.AutoResizeColumns();
grid2.AutoResizeRows();

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

if(grid2.PreferredSize.Height split2.Panel2.ClientSize.Height)
{
// Adjust splitter to fit columns WITH a vertical scrollbar present
split2.SplitterDistance =
Math.Max(100, ActiveForm.Width - sum + Split2.SplitterWidth - 35);
}
else
{
// Adjust to fit columns WITHOUT a vertical scrollbar present.
split2.SplitterDistance =
Math.Max(100, ActiveForm.Width - sum + Split2.SplitterWidth - 19);
}

I wish I knew how to directly determine if the vertical scrollbar is
present without using the PreferredSize.Height ClientSize.Height
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.Height 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
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...
2
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...
4
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...
3
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...
0
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...
1
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...
4
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...
0
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...
1
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...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.