VB.net Datagrid row height and scrolling problem!

I have a VB.net winforms application using a Datagrid which i have bound to a dataview.
I have to display quite alot of data in each row and therefore i have used the code below to set the row heights, which is a VB version of the C# code on syncfusion.  
The rowheights will set to the correct value ok, but if the bottom rows are expanded, the scroll bar wont allow me to scroll down to the bottom of the datagrid, and therefore you can not view them.  However if i select a row i can see and scroll down using the mouse wheel they come into view.  I have tried allsorts to try and refresh the grid so the scrollbar recognises the size but so far no luck.
Any ideas would be great...

The class i have used to expand the rows is below, followed by the code i have used in my main form to call it.

Imports System
Imports System.Reflection

Public Class DataGridRowHeightSetter
    Private dg As DataGrid
    Private rowObjects As ArrayList

    Public Sub New(ByVal dg As DataGrid)
        Me.dg = dg
    End Sub 'New

    Private Sub InitHeights()
        ' get the original type so that method info works.
        Dim t As Type = mainform.dataGridMain.GetType.BaseType
        Dim mi As MethodInfo = t.GetMethod("get_DataGridRows", BindingFlags.FlattenHierarchy Or BindingFlags.IgnoreCase Or BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public Or BindingFlags.Static)
        Dim dgra As System.Array = CType(mi.Invoke(Me.dg, Nothing), System.Array)
        rowObjects = New ArrayList
        Dim dgrr As Object
        For Each dgrr In dgra
            If dgrr.ToString().EndsWith("DataGridRelationshipRow") = True Then
            End If
        Next dgrr
    End Sub 'InitHeights

    Default Public Property Item(ByVal row As Integer) As Integer
                Dim pi As PropertyInfo = rowObjects(row).GetType().GetProperty("Height")
                Return Fix(pi.GetValue(rowObjects(row), Nothing))
                Throw New ArgumentException("invalid row index")
            End Try
        End Get
        Set(ByVal Value As Integer)
                Dim pi As PropertyInfo = rowObjects(row).GetType().GetProperty("Height")
                pi.SetValue(rowObjects(row), Value, Nothing)
                Throw New ArgumentException("invalid row index")
            End Try
        End Set
    End Property
End Class 'DataGridRowHeightSetter

    Private Sub expandRows()
            'create an instance of the DataGridRowHeightSetter class
            rowHeights = New DataGridRowHeightSetter(Me.dataGridMain)
            Dim rowCount As Integer = mdt_datatable.Rows.Count ' get number of rows in grid/datatable
            Dim Lines As Integer
            For i As Integer = 0 To rowCount - 1
                Lines = (CType(Me.dataGridMain.Item(i, 16), Integer) * (Me.dataGridMain.Font.Height + 3))
                    rowHeights(i) = Lines
                End If
            btnCollapse.Text = "Collapse"
            expanded = True
        Catch ex As Exception
        End Try
    End Sub
Who is Participating?
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.

Andy_WebsterAuthor Commented:
hmm ive found that this kind of works! but it isnt the best solution...

Dim vSB As VScrollBar = Nothing
        For Each c As Control In Me.dataGridMain.Controls
            If TypeOf c Is VScrollBar Then
                vSB = CType(c, VScrollBar)
            End If
vSB.Maximum += 10%
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.