Public Class GRID #Region "COLORES" Private BLANCO As Color = Color.White Private NEGRO As Color = Color.Black Private VERDE As Color = Color.LimeGreen Private ROJO As Color = Color.Red Private TOMATE As Color = Color.Tomato Private ROJO_OSCURO As Color = Color.DarkRed Private NARANJA As Color = Color.Orange Private AZUL As Color = Color.Navy Private AZUL_MENU As Color = Color.DodgerBlue Private GRIS As Color = Color.DarkGray Private AMARILLO As Color = Color.Yellow Private GOLD As Color = Color.Gold Private LEMON As Color = Color.LemonChiffon #End Region #Region "ALINEACIONES" Public CENTRO As DataGridViewContentAlignment = DataGridViewContentAlignment.MiddleCenter Public IZQUIERDA As DataGridViewContentAlignment = DataGridViewContentAlignment.MiddleLeft Public DERECHA As DataGridViewContentAlignment = DataGridViewContentAlignment.MiddleRight #End Region #Region "FUENTES" Public ARIAL As Integer Public ARIAL_BLACK As Integer Public VERDANA As Integer Public COMIC_SANS As Integer #End Region Public Grid As DataGridView Public L_Columnas As List(Of GRID_COLUMNA) Public Sub New(ObjGrid As DataGridView) Grid = ObjGrid L_Columnas = New List(Of GRID_COLUMNA) ' L_Columnas.Clear() Call CargaFuentes() End Sub #Region "PROPIEDADES" Private _Grid As DataGridView 'Public Property Grid() As DataGridView ' Get ' Return _Grid ' End Get ' Set(value As DataGridView) ' _Grid = value ' End Set 'End Property Private _nColumnas As Integer Public Property nColumnas() As Integer Get Return _nColumnas End Get Set(ByVal value As Integer) _nColumnas = value End Set End Property Private _Titulo As String Public Property Titulo() As String Get Return _Titulo End Get Set(ByVal value As String) _Titulo = value End Set End Property #End Region #Region "MÉTODOS PÚBLICOS" Public Sub Vaciar() Grid.Rows.Clear() End Sub Public Sub Refresca() Grid.Refresh() End Sub Public Sub Cabeceras() For i As Integer = 0 To Grid.Columns.Count - 1 Grid.Columns.Remove(Grid.Columns(0)) Next _nColumnas = L_Columnas.Count For i = 0 To L_Columnas.Count - 1 With L_Columnas(i) Grid.Columns.Add(.Nombre, .Texto) 'Grid.Columns(i).Width = .Ancho Grid.Columns(i).Width = DameAnchoCol(.Ancho) Grid.Columns(i).DefaultCellStyle.Alignment = .Alineacion Grid.Columns(i).Visible = .bVisible ' 1= True:0= False Grid.Columns(i).SortMode = .bOrdenable End With Next 'For i = 0 To Grid.Columns.Count - 1 ' MsgBox(i & " : " & Grid.Columns(i).Name) 'Next End Sub Public Sub FilaSelecciona(iFila As Integer, bUnica As Boolean) With Grid If bUnica Then .ClearSelection() : .CurrentCell = Nothing If iFila < 0 Then Exit Sub .Rows(iFila).Selected = True End With End Sub Public Sub FilaAgregar(Arr_Fila() As String) Grid.Rows.Add(Arr_Fila) End Sub Public Sub CeldaValor(iFila As Integer, iCol As Integer, Valor As String) Grid.Rows(iFila).Cells(iCol).Value = Valor End Sub Public Sub EstiloCabecera(Estilo As String) Dim COLOR_FONDO As Color, COLOR_FUENTE As Color Select Case Estilo Case "BLANCO" COLOR_FONDO = BLANCO : COLOR_FUENTE = NEGRO Case "VERDE" COLOR_FONDO = VERDE : COLOR_FUENTE = BLANCO Case "ROJO" COLOR_FONDO = ROJO : COLOR_FUENTE = BLANCO Case "NARANJA" COLOR_FONDO = NARANJA : COLOR_FUENTE = BLANCO Case "NEGRO" COLOR_FONDO = NEGRO : COLOR_FUENTE = BLANCO Case Else COLOR_FONDO = BLANCO : COLOR_FUENTE = NEGRO End Select With Grid .ColumnHeadersDefaultCellStyle.BackColor = COLOR_FONDO .ColumnHeadersDefaultCellStyle.ForeColor = COLOR_FUENTE .ColumnHeadersDefaultCellStyle.Font = New Font(FontFamily.Families(ARIAL_BLACK), 10, FontStyle.Bold, GraphicsUnit.Point) .ColumnHeadersHeight = 30 .RowHeadersDefaultCellStyle.SelectionBackColor = AZUL_MENU .EnableHeadersVisualStyles = False End With End Sub Public Sub EstiloGrid(Estilo As String) Dim COLOR_FONDO As Color, COLOR_FUENTE As Color Select Case Estilo Case "BLANCO" COLOR_FONDO = BLANCO : COLOR_FUENTE = NEGRO Case "VERDE" COLOR_FONDO = VERDE : COLOR_FUENTE = BLANCO Case "ROJO" COLOR_FONDO = ROJO : COLOR_FUENTE = BLANCO Case "NARANJA" COLOR_FONDO = NARANJA : COLOR_FUENTE = BLANCO Case "NEGRO" COLOR_FONDO = NEGRO : COLOR_FUENTE = BLANCO Case Else COLOR_FONDO = BLANCO : COLOR_FUENTE = NEGRO End Select With Grid .DefaultCellStyle.BackColor = COLOR_FONDO .DefaultCellStyle.ForeColor = COLOR_FUENTE .DefaultCellStyle.Font = New Font(FontFamily.Families(VERDANA), 8, FontStyle.Bold, GraphicsUnit.Point) .DefaultCellStyle.SelectionBackColor = AZUL_MENU .EnableHeadersVisualStyles = False .RowTemplate.Height = 12 ' .RowTemplate.Height = DameAnchoFilas(.Rows.Count) End With End Sub Public Sub EstiloFila(iFila As Integer, sEstilo As String) Dim COLOR_FONDO As Color, COLOR_FUENTE As Color Select Case sEstilo Case "BLANCO" COLOR_FONDO = BLANCO : COLOR_FUENTE = NEGRO Case "AMARILLO" COLOR_FONDO = AMARILLO : COLOR_FUENTE = NEGRO Case "GOLD" COLOR_FONDO = GOLD : COLOR_FUENTE = NEGRO Case "LEMON" COLOR_FONDO = LEMON : COLOR_FUENTE = NEGRO Case "VERDE" COLOR_FONDO = VERDE : COLOR_FUENTE = BLANCO Case "ROJO" COLOR_FONDO = ROJO : COLOR_FUENTE = BLANCO Case "TOMATE" COLOR_FONDO = TOMATE : COLOR_FUENTE = BLANCO Case "NARANJA" COLOR_FONDO = NARANJA : COLOR_FUENTE = BLANCO Case "NEGRO" COLOR_FONDO = NEGRO : COLOR_FUENTE = BLANCO Case Else COLOR_FONDO = BLANCO : COLOR_FUENTE = NEGRO End Select With Grid .Rows(iFila).DefaultCellStyle.BackColor = COLOR_FONDO .Rows(iFila).DefaultCellStyle.ForeColor = COLOR_FUENTE .Font = New Font(.Font, FontStyle.Bold) End With End Sub #End Region #Region "MÉTODOS PRIVADOS" Private Sub CargaFuentes() For i = 0 To FontFamily.Families.Count - 1 'Debug.Print(i & " " & FontFamily.Families(i).Name) 'Console.Write(FontFamily.Families(i).Name) Select Case FontFamily.Families(i).Name Case "Arial" : ARIAL = i Case "Arial Black" : ARIAL_BLACK = i Case "Verdana" : VERDANA = i Case "Comic Sans MS" : COMIC_SANS = i End Select Next End Sub Private Function DameAnchoCol(Porcentaje As Integer) As Integer DameAnchoCol = 10 If Porcentaje = 0 Then DameAnchoCol = 0 : Exit Function Dim AnchoGrid As Integer = Grid.Width - 44.8 DameAnchoCol = (Porcentaje * AnchoGrid) / 100 End Function Private Function DameAnchoFilas(nFilas As Integer) As Integer DameAnchoFilas = 10 If nFilas < 1 Then Exit Function Dim AltoGrid As Integer = Grid.Height - Grid.ColumnHeadersHeight DameAnchoFilas = AltoGrid / nFilas End Function #End Region End Class Public Class GRID_COLUMNA Public Sub New(sNombre As String, sTexto As String, iAncho As Integer, Alinea As DataGridViewContentAlignment, Optional bEsVisible As Boolean = True, Optional bOrdena As Integer = 1) _Nombre = sNombre : _Texto = sTexto : _Ancho = iAncho : _Alineacion = Alinea : _bVisible = bEsVisible : _bOrdenable = bOrdena End Sub #Region "PROPIEDADES" Private _Nombre As String Public Property Nombre() As String Get Return _Nombre End Get Private Set(ByVal value As String) _Nombre = value End Set End Property Private _Texto As String Public Property Texto() As String Get Return _Texto End Get Private Set(ByVal value As String) _Texto = value End Set End Property Private _Ancho As String Public Property Ancho() As String Get Return _Ancho End Get Private Set(ByVal value As String) _Ancho = value End Set End Property Private _Alineacion As DataGridViewContentAlignment Public Property Alineacion() As DataGridViewContentAlignment Get Return _Alineacion End Get Private Set(ByVal value As DataGridViewContentAlignment) _Alineacion = value End Set End Property Private _bOrdenable As Integer Public Property bOrdenable() As Integer Get Return _bOrdenable End Get Private Set(ByVal value As Integer) _bOrdenable = value End Set End Property Private _bVisible As Boolean Public Property bVisible As Boolean Get Return _bVisible End Get Private Set(ByVal value As Boolean) _bVisible = value End Set End Property #End Region End Class
Comments