lonewolf32 Posted July 27, 2007 Posted July 27, 2007 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. Quote
mandelbrot Posted August 1, 2007 Posted August 1, 2007 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. Quote
hecktarzuli Posted August 29, 2007 Posted August 29, 2007 Just check datagridview.PreferredSize.Height property. If it is greater than datagridview.Height, then the scrollbar is visible. Quote
hecktarzuli Posted August 29, 2007 Posted August 29, 2007 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.