Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I figured out how to determine the width of the vertical scroll bar in the datagrid view (using SystemInformation namespace) but I found no clue as to how to determine if it is displayed or not (i.e. do I have enough rows in my dgv to cause it to be displayed). I am computing column widths during the resize event of the dgv but the fact that the vertical scroll bar is present or not present comes into play.

 

Does any one know how to tell if the vertical scroll bar is displayed in a datagridview?

 

Thanks.

Posted

Hi Lonewolf,

 

 

I don't know of any 'simple' way of doing it, but you could use something like this (it does need tidying up, though)...

With dgvInfo
   'The 2 adds a small arbetrary amount on to get past the borders...
   Dim topAdd As Int32 = 2
   'Check to see if a header row is displayed...
   If .RowHeadersVisible Then topAdd += .Rows(0).Height
   'Get a top and bottom point row object index..
   Dim top As DataGridView.HitTestInfo = .HitTest(2, topAdd)
   Dim bot As DataGridView.HitTestInfo = .HitTest(.Right - 2, .Bottom - 2)
   'Check to see if the number of rows displayed is less than the number of rows in the list...
   Dim sbVis As Boolean = top.RowIndex - bot.RowIndex < .RowCount
End With

 

There's probably a better way, as this isn't really the cleanest method. Also, I've forgotten to take the horizontal scrollbar into account - you'll need to code for this too.

 

 

Paul.

  • 4 weeks later...
Posted

Yet another way is:

 

detect if dataGridView.Controls[1].Visible = true

 

Control 0 = Horizontal Scroll Bar

Control 1 = Vertical Scroll Bar

 

You can also get the width with this if you want something more precise. Cast as a scroll bar and the possibilities are endless.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...