Problema al llenar el MSHFlexgrid despues de la primera ves !!!!!!!!
Hola a todos:
Ayudenme por favor!
Tengo un problema que espero me puedan ayudar .
Problema
------------
<FONT color=#7f0000>Lo que sucede es que cuando uso la Funcion que me devuelve los registros la primera ves de me 4 regisros y uso mi funcion de LLENARGRILLA y pinta normal los 4 registros que tengo en mi tabla pero despues de haber llenado mi datos en el GRID uso mi Function de BORRARFILAS y me borro por ejemplo la 2 ultimas filas la demas veces que uso de nuevo mi funcion de LLENARGRILLA me pinta solo dos registros cuando el recordset tiene en realidad 4 .
Estuve haciendo pruebas para verificar que no sea el Recordset pero estaba bien lo que sucede es que al parecer si tengo 4 registros pintados en el Grd y me borro 2 la siguientes ves que lo llene ma saldran todos menos 2
Debe tener algo que ver con el RemoveITEM por favor si alguien sabe porque sucede esto o la solucion se los agradecere mucho. </FONT>
Les adjunto las funciones para que me puedan enterder mejor
Funciones
********
<FONT color=#0000bf>Public Sub LlenarGrilla(ByVal Grd As MSHFlexGrid, ByVal Rs As ADODB.Recordset)</FONT>Dim iCol As Integer, iFila As Integer, lColSize() As Long
With Grd
.Clear
.BackColor = vbWhite
.Enabled = True
If Rs.RecordCount = 0 Then
Poner Cabeceras
.Rows = Rs.RecordCount + 2
.Cols = Rs.Fields.Count + 1
.BackColor = &H8000000F
.Enabled = False
For iFila = 1 To Rs.Fields.Count
.TextMatrix(0, iFila) = Rs.Fields(iFila - 1).Name
.ColAlignmentFixed(iFila) = flexAlignCenterCenter
Next
Exit Sub
End If
.Rows = Rs.RecordCount + 1
.Cols = Rs.Fields.Count + 1
Poner Cabeceras
For iFila = 1 To Rs.Fields.Count
.TextMatrix(0, iFila) = Rs.Fields(iFila - 1).Name
Next
ReDim lColSize(Rs.Fields.Count - 1)
Llenar de Datos
For iFila = 1 To Rs.RecordCount
For iCol = 1 To Rs.Fields.Count
.TextMatrix(iFila, iCol) = CStr(IIf(IsNull(Rs.Fields(iCol - 1).Value), Space(1), Rs.Fields(iCol - 1).Value))
lColSize(iCol - 1) = lColSize(iCol - 1) + IIf(IsNull(Rs.Fields(iCol - 1).Value), 0, Len(Trim(Rs.Fields(iCol - 1).Value))) * 170
Next
Rs.MoveNext
Next
Efecto de Selecion
On Error Resume Next
.Col = IIf(LastCol = 0, 1, LastCol)
.Row = 1
.CellBackColor = &H8000000D
.CellForeColor = vbWhite
Aliniar y tamaño
For iFila = 1 To .Cols - 1
.ColAlignmentFixed(iFila) = flexAlignCenterCenter
.ColAlignment(iFila) = flexAlignLeftBottom
.ColWidth(iFila) = IIf(Val(Len(Trim(Rs.Fields(iFila - 1).Name))) * 150 > lColSize(iFila - 1) / Rs.RecordCount - 1, Val(Len(Trim(Rs.Fields(iFila - 1).Name))) * 150, lColSize(iFila - 1) / Rs.RecordCount - 1)
Next
.ColWidth(0) = 200
End With
<FONT color=#0000bf>End Sub</FONT>
<FONT color=#00007f>Private Sub BorrarFilas()</FONT>
Borrar las filas seleccionadas
Dim lFilaMayor As Long, lFilaMenor As Long, AuxFila As Long, lFila As Long
Borrar siempre desde la fila mayor a la menor
lFilaMayor = GrdDetOrd.Row
lFilaMenor = GrdDetOrd.RowSel
If lFilaMayor < lFilaMenor Then
AuxFila = lFilaMayor
lFilaMayor = lFilaMenor
lFilaMenor = AuxFila
End If
Dim lCol As Long
If lFilaMenor = 1 Then lFilaMenor = lFilaMenor + 1: Beep
For lFila = lFilaMayor To lFilaMenor Step -1
If lFila = 1 And GrdDetOrd.Rows = 2 Then
GrdDetOrd.ClearStructure
GrdDetOrd.FormatString = Space(5) & vbTab & "Cantidad" & Space(5) & vbTab & "Codigo" & Space(5) & vbTab & "Articulo" & Space(15) & vbTab & "Precio Unit." & Space(5) & vbTab & "Descto%" & Space(5) & vbTab & "Total" & Space(5)
Else
GrdDetOrd.RemoveItem lFila
End If
Next
LastRowDet = GrdDetOrd.Rows - 1
LastColDet = 1
GrdDetOrd.Col = LastColDet
GrdDetOrd.Row = LastRowDet
GrdDetOrd.RowSel = LastRowDet
GrdDetOrd.ColSel = LastColDet
<FONT color=#0000bf>End Sub</FONT>
<FONT color=#00007f>Public Function TraeRegitros(ByVal sSql As String) As ADODB.Recordset</FONT>
On Error GoTo Lbl_error
If gEstConex <> True Then gEstConex = ConectarVJS(GetSetting("PedidoVJS", "Data", "Data Source", Empty))
If gRs.State <> adStateClosed Then gRs.Close
gRs.Open sSql, gCnConexion, adOpenStatic, 3
MsgBox gRs.RecordCount
Set TraeRegitros = gRs
Exit Function
Lbl_error:
MsgBox "Error en Traer Registros " & vbCrLf & _
"Numero : " & Err.Number & vbCrLf & _
"Descripcion : " & Err.Description & vbCrLf & _
"Origen : " & Err.Source & vbCrLf & _
"Modulo : Acceso a Datos" & vbCrLf & _
"Funcion : TraeRegistros " & vbCrLf _
, vbCritical
Call DesconectarConexion
<FONT color=#0000bf>End Function</FONT>