Tema: FAQ's de VB6
Ver Mensaje Individual
  #21 (permalink)  
Antiguo 04/09/2004, 19:56
Avatar de GeoAvila
GeoAvila
Colaborador
 
Fecha de Ingreso: diciembre-2003
Ubicación: Antigua Guatemala
Mensajes: 4.032
Antigüedad: 20 años, 4 meses
Puntos: 53
Grid Editable 2

Código:
 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
 	' Guardar los datos del grid
 	GuardarDatos
 End Sub
 
 Private Sub Form_Resize()
 	' Reajustar el tamaño del grid al de la ventana
 	' Si tuviesemos otro control, por ejemplo una barra de estado,
 	' restarle el ancho de la misma al Grid
 	If WindowState <> vbMinimized Then
 		Grid2.Move 0, 0, ScaleWidth, ScaleHeight - picStatus.Height
 		With cmdSalir
 			.Left = picStatus.ScaleWidth - .Width - 90
 			lblStatus.Width = .Left - 120 - lblStatus.Left
 		End With
 	End If
 End Sub
 
 Private Sub Grid2_Click()
 	' Cuando se hace un sólo click en otra columna,
 	' asigna el valor seleccionado, (como si se pulsara intro)
 	AsignarCelda
 End Sub
 
 Private Sub Grid2_DblClick()
 	' Editar al hacer dobleclick
 	LastRow = Grid2.Row
 	LastCol = Grid2.Col
 	'
 	OcultarControles
 	'
 	MostrarCelda
 End Sub
 
 Private Sub Grid2_KeyDown(KeyCode As Integer, Shift As Integer)
 	' Editar si se pulsa F2
 	If KeyCode = vbKeyF2 Then
 		MostrarCelda
 	ElseIf KeyCode = vbKeyDelete Then
 		' Borrar las filas seleccionadas						    (13/May/01)
 		BorrarFilas
 	End If
 End Sub
 
 Private Sub Grid2_KeyPress(KeyAscii As Integer)
 	Select Case KeyAscii
 	' Si se pulsa Intro, editar la celda
 	Case vbKeyReturn
 		KeyAscii = 0
 		MostrarCelda
 	' Cancelar si se pulsa ESC
 	Case vbKeyEscape
 		KeyAscii = 0
 		AsignarCelda
 	' Si se pulsa cualquier letra, editar la celda
 	Case 32 To 255
 		MostrarCelda
 		With Text1
 	  	  If .Visible Then
 			    '.Text = .Text & Chr$(KeyAscii)
 				.Text = Chr$(KeyAscii)
 				.SelStart = Len(.Text) + 1
 			End If
 		End With
 	End Select
 End Sub
 
 Private Sub Grid2_Scroll()
 	' Comprobar si la columna en la que está el control está visible
 	' si es así, ocultar los controles
 	'
 	If Grid2.ColIsVisible(LastCol) = False Then
 		OcultarControles
 		Exit Sub
 	End If
 	If Grid2.RowIsVisible(LastRow) = False Then
 		OcultarControles
 		Exit Sub
 	End If
 	' Comprobar si estaba visible antes de ocultarlo
 	' y posicionarlo en la misma celda
 	If ControlVisible Then
 		MostrarCelda
 	End If
 End Sub
 
 Private Sub MostrarCelda()
 	Static YaEstoy As Boolean
 	'
 	' Salir si es una de las celdas fijas
 	If Grid2.Col <= Grid2.FixedCols - 1 Or Grid2.Row <= Grid2.FixedRows - 1 Then
 		Exit Sub
 	End If
 	'
 	If YaEstoy Then Exit Sub
 	YaEstoy = True
 	'
 	OcultarControles
 	'
 	LastRow = Grid2.Row
 	LastCol = Grid2.Col
 	'
 	' Si es una nueva celda
 	With Grid2
 		If .TextMatrix(LastRow, 0) = cNuevaFila Then
 			.Rows = .Rows + 1
 			.TextMatrix(LastRow, 0) = LastRow
 			.TextMatrix(.Rows - 1, 0) = cNuevaFila
 		End If
 	End With
 	'
 	Select Case LastCol
 	Case 2
 		Combo1.Text = Grid2.TextMatrix(LastRow, LastCol)
 		Combo1.Move Grid2.CellLeft - Screen.TwipsPerPixelX, Grid2.CellTop - Screen.TwipsPerPixelY
 		Combo1.Width = Grid2.CellWidth + Screen.TwipsPerPixelX * 2
 		Combo1.Visible = True
 		Combo1.ZOrder
 		Combo1.SetFocus
 	Case Else
 		Text1.Move Grid2.CellLeft - Screen.TwipsPerPixelX, Grid2.CellTop - Screen.TwipsPerPixelY, Grid2.CellWidth + Screen.TwipsPerPixelX * 2, Grid2.CellHeight + Screen.TwipsPerPixelY * 2
 		Text1.Text = Grid2.Text
 		If Len(Grid2.Text) = 0 Then
 			If LastRow > 1 Then
 				Text1.Text = Grid2.TextMatrix(LastRow - 1, LastCol)
 			End If
 		End If
 		Text1.Visible = True
 		If Text1.Visible Then
 			Text1.ZOrder
 			Text1.SetFocus
 		End If
 	End Select
 	'
 	ControlVisible = True
 	'
 	YaEstoy = False
 End Sub
 
 Private Sub SiguienteCelda()
 	If Grid2.Col < Grid2.Cols - 1 Then
 		Grid2.Col = Grid2.Col + 1
 	Else
 		Grid2.Col = 1
 		If Grid2.Row < Grid2.Rows - 1 Then
 			Grid2.Row = Grid2.Row + 1
 		End If
 	End If
 End Sub
 
 Private Sub Text1_GotFocus()
 	With Text1
 		' Posicionar el cursor al final
 		.SelStart = Len(.Text)
 	End With
 End Sub
 
 Private Sub Text1_KeyPress(KeyAscii As Integer)
 	' Si se pulsa Intro, aceptar lo que se ha escrito
 	If KeyAscii = vbKeyReturn Then
 		KeyAscii = 0
 		AsignarCelda
 		SiguienteCelda
 	' Si se pulsa ESC, cancelar la edición
 	ElseIf KeyAscii = vbKeyEscape Then
 		KeyAscii = 0
 		Text1.Visible = False
 		ControlVisible = False
 	End If
 End Sub
 
 Private Sub AsignarCelda()
 	' Asignar al grid el texto escrito o seleccionado del combo
 	Dim s As String
 	'
 	OcultarControles
 	ControlVisible = False
 	'
 	' Asignar el texto anterior a la celda
 	Select Case LastCol
 	Case 2
 		'
 		Grid2.TextMatrix(LastRow, LastCol) = Combo1.Text
 	Case Else
 		s = Text1.Text
 		' si es la columna de la fecha...
 		If LastCol = 1 Then ' Fecha
 			s = AjustarFecha(s)
 		End If
 		Grid2.TextMatrix(LastRow, LastCol) = s
 	End Select
 End Sub
 
  
__________________
* Antes de preguntar lee las FAQ, y por favor no hagas preguntas en las FAQ
Sitio http://www.geoavila.com twitter: @GeoAvila