Visual Basic - ayuda con MSHFlexGrid

Life is soft - evento anual de software empresarial
 
Vista:

ayuda con MSHFlexGrid

Publicado por Marboro (9 intervenciones) el 27/02/2009 16:16:36
este el el codigo, quiero que cuando al ir digitando una letra me filtre todo los que conside con la letra esto en Flex1 y en flex2 me liste todos los que tienes el mismo nemonico de los que estoy buscando

Agradeceria mucho tu ayuda

Option Explicit

Public KeyRetroceso As Boolean
Public Cadena As String 'string que contiene la cadena de conexion
Public iSql As String 'string que contiene la instruccioón SQL
Public Usuario As String 'identifica el nombre de usuario

Public Declare Sub InitCommonControls Lib "comctl32" ()

Public ConnPublic As ADODB.Connection 'cadena de conexión de accseso a datos ADO
Public rsPublic As ADODB.Recordset 'recordset de accseso a datos ADO

Public cnn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public sr As New ADODB.Recordset

Private Sub Form_Load()
' Abre la conexión
Call IniciarConexion
' carga el Recorset con todos los datos
rs.Open "select * from obras", cnn, adOpenStatic, adLockOptimistic
' llena el flexgrid
sr.Open "select * from nemonico", cnn, adOpenStatic, adLockOptimistic
Call CargarFlex1(Flex1)
Call CargarFlex2(Flex2)
End Sub

Sub CargarFlex1(Flex1 As MSHFlexGrid)
Set Flex1.DataSource = rs
With Flex1
.ColWidth(0) = 800
.ColWidth(1) = 17000
.ColAlignmentFixed(0) = 1
.ColAlignment(0) = 1
End With
End Sub

Sub CargarFlex2(Flex2 As MSHFlexGrid)
Set Flex2.DataSource = sr
With Flex2
.ColWidth(1) = 800
.ColWidth(2) = 800
.ColWidth(3) = 800
.ColWidth(4) = 800
.ColWidth(4) = 800
.ColWidth(6) = 800
.ColWidth(7) = 6000
.ColWidth(8) = 800
.ColAlignmentFixed(0) = 1
.ColAlignment(0) = 1
End With
End Sub

Public Sub IniciarConexion()
With cnn
.CursorLocation = adUseClient
.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "obras.mdb" & ";Persist Security Info=False"
End With

End Sub

Function Autocompletar_MSHFlexGrid(MSHFlexGrid As Object, TBox As TextBox, columna As Long)

Dim i, j As Integer
Dim pos_SelStart As Integer

Set ConnPublic = New ADODB.Connection
Set rsPublic = New ADODB.Recordset

If (KeyRetroceso Or Len(TBox.Text) = 0) Then
KeyRetroceso = False
Exit Function
End If

With MSHFlexGrid
'Recorremos todas las filas del MshFlexgrid
For i = 0 To .Rows - 1
'Busca en el flexgrid si hay coincidencia, en la fila y columna actual
If InStr(1, .TextMatrix(i, columna), TBox.Text, vbTextCompare) = 1 Then
pos_SelStart = TBox.SelStart
'Asignamos el valor de la celda actual al textbox
TBox.Text = .TextMatrix(i, columna)
'Indicamos el comienzo de la selección
TBox.SelStart = pos_SelStart
'seleccionamos la porción de texto en el Text
TBox.SelLength = Len(.TextMatrix(i, columna)) - pos_SelStart
'Establecemos con TopRow , la fila arriba de todo
.TopRow = i
End If
Next i
End With

End Function
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:ayuda con MSHFlexGrid

Publicado por P3L30N2009 (699 intervenciones) el 27/02/2009 17:42:02
Creo que te complicas demasiado la vida. Con este código mostramos el el Grid los registros coincidentes segú la tecla que se pulse.

Private Sub Text1_Change()
Dim i As Integer
Dim rs As New ADODB.Recordset
With rs
.ActiveConnection = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=" & App.Path & "MiDB.mdb"
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.Open "Select * From LaTabla WHERE Nombre LIKE'" & Text1 & "%'"
End With
If rs.RecordCount = 0 Then
MsgBox "No hay coincidencias"
Exit Sub
End If
With MSFlexGrid1
.Cols = rs.Fields.Count
For i = 0 To .Cols - 1
.TextMatrix(0, i) = rs.Fields(i).Name
Next i
.Rows = rs.RecordCount + 1
.Row = 1
.Col = 0
.RowSel = .Rows - 1
.ColSel = .Cols - 1
.Clip = rs.GetString(, rs.RecordCount)
.Row = 1
End With
' aquí formateas las columnas del grid a tu gusto
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar