Modificar la altura de las líneas de un DataGrid
Artículo por Club Developers · 11 mayo 2006
2222 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
Option Explicit On Option Strict On Imports System Imports System.Reflection Imports System.Windows.Forms Public Class MiDataGrid Inherits DataGrid Public Sub New() MyBase.New End Sub Public Sub setRowHeight(ByVal rowindex As Integer, ByVal rowheight As Integer) Dim rows() As Object = GetRows() If rowindex < 0 Then For Each row As Object In rows setHeight(row, rowheight) Next Else : setHeight(rows(rowindex), rowheight) End If End Sub Private Function GetRows() As Object() Dim bf As BindingFlags = BindingFlags.Instance Or BindingFlags.NonPublic Dim t As Type = Me.GetType.BaseType Dim mi As MethodInfo = t.GetMethod("get_DataGridRows", bf) Return CType((mi.Invoke(Me, Nothing)), Object()) End Function Private Sub setHeight(ByVal row As Object, ByVal rowheight As Integer) row.GetType().GetProperty("Height").SetValue(row, rowheight, Nothing) End Sub End Class