Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Meter un checkbox en datagrid

Estas en el tema de Meter un checkbox en datagrid en el foro de Visual Basic clásico en Foros del Web. Buenas tardes: He intentado meter un checkbox en datagrid, algo que en un principio parece facil: Boton derecho sobre el datagrid, pestaña formato, selecionamos columan ...
  #1 (permalink)  
Antiguo 10/05/2007, 05:27
 
Fecha de Ingreso: mayo-2007
Mensajes: 3
Antigüedad: 17 años
Puntos: 0
Meter un checkbox en datagrid

Buenas tardes:

He intentado meter un checkbox en datagrid, algo que en un principio parece facil:
Boton derecho sobre el datagrid, pestaña formato, selecionamos columan y le damos a formato checkbox.

He seguido estos pasos y no hay forma, no me funciona.
En mi caso el campo que quiero poner vinculado con el checkbox es de tipo boolean (o bit para sql server 7), sin embargo no funciona.
En vez del checkbox me aprece un triste campo con un 0.

Muchas gracias.
  #2 (permalink)  
Antiguo 14/05/2007, 05:16
 
Fecha de Ingreso: mayo-2007
Mensajes: 3
Antigüedad: 17 años
Puntos: 0
Re: Meter un checkbox en datagrid

Por favor ayuda

  #3 (permalink)  
Antiguo 14/05/2007, 05:37
 
Fecha de Ingreso: mayo-2007
Mensajes: 74
Antigüedad: 17 años
Puntos: 1
Re: Meter un checkbox en datagrid

Esto ejemplo usa lo más parecido a un checkbox en un datagrid que he visto.

Form con un datagrid DGrid y este código:

Option Explicit
Dim mRS As ADODB.Recordset
Dim CBCharacters(1) As String

Private Sub CreateRS()
Set mRS = New ADODB.Recordset
With mRS
.Fields.Append "ID", adInteger
.Fields.Append "Text", adVarWChar, 32
.Fields.Append "Bool", adBoolean
.LockType = adLockOptimistic
.Open
End With
End Sub

Private Sub FillRS(NumRecords As Long)
Dim RCount As Long

Select Case True
Case mRS Is Nothing
Case mRS.State And adStateOpen = adStateOpen
With mRS
RCount = .RecordCount + NumRecords
Do While .RecordCount < RCount
.AddNew
.Fields(0).Value = .RecordCount
.Fields(1).Value = Chr$(Int(65 * Rnd) + 65)
.Fields(2).Value = (.RecordCount Mod 2 = 0)
.Update
Loop
End With
End Select
End Sub

Private Sub DGrid_HeadClick(ByVal ColIndex As Integer)
mRS.Sort = mRS.Fields(ColIndex).Name
End Sub

Private Sub DGrid_KeyDown(KeyCode As Integer, Shift As Integer)
If DGrid.Col = 2 Then
KeyCode = 0
DGrid.Columns(2).Value = Not DGrid.Columns(2).Value
End If
End Sub

Private Sub DGrid_KeyPress(KeyAscii As Integer)
If DGrid.Col = 2 Then
KeyAscii = 0
End If
End Sub

Private Sub DGrid_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If DGrid.RowContaining(Y) > -1 Then
If DGrid.ColContaining(X) > -1 Then
DGrid.Row = DGrid.RowContaining(Y)
End If
End If
End Sub

Private Sub DGrid_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If DGrid.RowContaining(Y) > -1 Then
If DGrid.ColContaining(X) = 2 Then
DGrid.Columns(2).Value = Not DGrid.Columns(2).Value
End If
End If
End Sub

Private Sub Form_Load()
Dim DF As StdDataFormat
CBCharacters(0) = "."
CBCharacters(1) = "X"

CreateRS
FillRS 100
Set DGrid.DataSource = mRS
Set DF = New StdDataFormat
With DF
.Type = fmtBoolean
.FalseValue = CBCharacters(0)
.TrueValue = CBCharacters(1)
.NullValue = ""
End With
Set DGrid.Columns(2).DataFormat = DF
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Set DGrid.DataSource = Nothing
Select Case True
Case mRS Is Nothing
Case mRS.State And adStateOpen = adStateOpen
If mRS.EditMode <> adEditNone Then
mRS.Update
End If
mRS.Close
End Select
Set mRS = Nothing
End Sub

Private Sub Form_Resize()
DGrid.Move 90, 90, Me.ScaleWidth - 180, Me.ScaleHeight - 180
End Sub


Para mejorar esto y usar un checkbox "de verdad" habría que usar otro control (de terceros) como el Spread (FarPoint).
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:24.