[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 971
  • Last Modified:

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
        InitHeights()
    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
                rowObjects.Add(dgrr)
            End If
        Next dgrr
    End Sub 'InitHeights

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





    Private Sub expandRows()
        Try
            '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
            Next
            Me.dataGridMain.Invalidate()
            btnCollapse.Text = "Collapse"
            expanded = True
        Catch ex As Exception
            ReportError(ex)
        End Try
    End Sub
0
Andy_Webster
Asked:
Andy_Webster
1 Solution
 
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
        Next
       
vSB.Maximum += 10%
        Me.dataGridMain.PerformLayout()
        Me.dataGridMain.Invalidate()
0
 
EE_AutoDeleterCommented:
Andy_Webster,
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.

EE_AutoDeleter
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now