Modificar la altura de las líneas de un DataGrid

2120 vistas

Vamos a ver cómo podemos cambiar la altura de las filas de un DataGrid mediante un ejemplo en el que definiremos nuestra propia clase DataGrid



vbnet
  1. Option Explicit On
  2. Option Strict On
  3.  
  4. Imports System
  5. Imports System.Reflection
  6. Imports System.Windows.Forms
  7.  
  8. Public Class MiDataGrid
  9.   Inherits DataGrid
  10.  
  11.   Public Sub New()
  12.     MyBase.New
  13.   End Sub
  14.  
  15.   Public Sub setRowHeight(ByVal rowindex As Integer, ByVal rowheight As Integer)
  16.     Dim rows() As Object = GetRows()
  17.  
  18.     If rowindex < 0 Then
  19.       For Each row As Object In rows
  20.         setHeight(row, rowheight)
  21.       Next
  22.     Else : setHeight(rows(rowindex), rowheight)
  23.     End If
  24.   End Sub
  25.  
  26.   Private Function GetRows() As Object()
  27.     Dim bf As BindingFlags = BindingFlags.Instance Or BindingFlags.NonPublic
  28.     Dim t As Type = Me.GetType.BaseType
  29.     Dim mi As MethodInfo = t.GetMethod("get_DataGridRows", bf)
  30.     Return CType((mi.Invoke(Me, Nothing)), Object())
  31.   End Function
  32.  
  33.   Private Sub setHeight(ByVal row As Object, ByVal rowheight As Integer)
  34.     row.GetType().GetProperty("Height").SetValue(row, rowheight, Nothing)
  35.   End Sub
  36.  
  37. End Class