FLEX GRID

GUIGOR 18/04/2014 23:23:22
#437424
Boa noite

amigos estou colocando os dado em fum flex grid assim :

[ô]CARREGA DADOS E COLOCA OS DADOS NO GRID FLEX GRID
Sub CarregaDados()
Dim Soma As Double


Set rs = New ADODB.Recordset

rs.Open [Ô]SELECT a.codp, b.descricao, a.quant as quantidade, a.pcatl as preco [Ô] & _
[Ô]from balanco a, cad_produto b [Ô] & _
[Ô]where a.codp = b.codp and mesano = [ô][Ô] & TextMesAnoManutencao & [Ô][ô] order by b.descricao[Ô], con, adOpenKeyset, adLockOptimistic
With rs
DoEvents
If .BOF = True And .EOF = True Then Exit Sub
DoEvents
Grid.rows = .RecordCount + 1
Do Until .EOF = True
DoEvents
Row = Row + 1
Grid.TextMatrix(Row, 0) = !codp
Grid.TextMatrix(Row, 1) = !descricao
Grid.TextMatrix(Row, 2) = Format(!QUANTIDADE, [Ô]#,##0.00[Ô])
Grid.TextMatrix(Row, 3) = Format(CDec(!Preco), [Ô]#,##0.00[Ô])
Grid.TextMatrix(Row, 4) = Format(CDec(Grid.TextMatrix(Row, 3)) * CDec(Grid.TextMatrix(Row, 2)), [Ô]#,##0.00[Ô])

Soma = Soma + CDbl(Grid.TextMatrix(Row, 4))

.MoveNext
Loop
End With
txt_vlrtot.Text = Soma
End Sub

o que acontece quanto eu faço isso pela primeira vez ele faz tudo sem problema, sendo que quando eu mando ele repetir essa rotina apresenta o seguinte erro:

Subscript out of range e quando clico em debug ele para aqui:

e outra coisa gostaria de saber como eu posso excluir uma linha inteira do flex grid.

desde ja muito obrigado
ANDPAG 19/04/2014 04:48:15
#437426
tente assim, tire a linha Grid.rows = .RecordCount + 1 e coloque dentro do seu Do Events assim:

Grid.AddItem vbNullString

Grid.TextMatrix(grid.Rows -1, 0) = !codp
Grid.TextMatrix(grid.Rows -1, 1) = !descricao
Grid.TextMatrix(grid.Rows -1, 2) = Format(!QUANTIDADE, [Ô]#,##0.00[Ô])
Grid.TextMatrix(grid.Rows-1, 3) = Format(CDec(!Preco), [Ô]#,##0.00[Ô])
Grid.TextMatrix(grid.Rows-1, 4) = Format(CDec(Grid.TextMatrix(grid.Rows-1, 3)) * CDec(Grid.TextMatrix(grid.Rows-1, 2)), [Ô]#,##0.00[Ô])

Soma = Soma + CDbl(Grid.TextMatrix(Grid.Rows - 1, 4))

.MoveNext
Loop
End With

Abs
NILSONTRES 19/04/2014 07:50:32
#437427
Resposta escolhida
RSFita.Open [Ô]Select *from Troco Where Data=#[Ô] & Format(DataFCaixa, [Ô]mm/dd/yyyy[Ô]) & [Ô]# And Fechado=False And Maquina=[ô][Ô] & sGetComputerName & [Ô][ô] Order by Maquina,NPedido ;[Ô], Conexao, 3, 3

Grid1.Rows = 1
Grid1.Redraw = False
While Not RSFita.EOF
With Grid1
.TextMatrix(.Rows - 1, 1) = [Ô][Ô] & RSFita!NPedido
.TextMatrix(.Rows - 1, 2) = [Ô][Ô] & FormatNumber(RSFita!ValorVenda, 2)
.TextMatrix(.Rows - 1, 3) = [Ô][Ô] & FormatNumber(RSFita!VLRDinheiro, 2)
.TextMatrix(.Rows - 1, 4) = [Ô][Ô] & FormatNumber(RSFita!VLRCheque, 2)
.TextMatrix(.Rows - 1, 5) = [Ô][Ô] & FormatNumber(RSFita!VLRCartao, 2)
.TextMatrix(.Rows - 1, 6) = [Ô][Ô] & FormatNumber(RSFita!ValorTroco, 2)
.TextMatrix(.Rows - 1, 7) = [Ô][Ô] & RSFita!Usuario
.TextMatrix(.Rows - 1, 8) = [Ô][Ô] & RSFita!Maquina
.Rows = .Rows + 1
End With
RSFita.MoveNext
Wend
RSFita.Close
Set RSFita = Nothing
Grid1.Rows = Grid1.Rows - 1
Grid1.Redraw = True
MARCELO.TREZE 19/04/2014 19:31:28
#437442
pra mim é algo mais simples

Sub CarregaDados()
Dim Soma As Double


Set rs = New ADODB.Recordset

rs.Open [Ô]SELECT a.codp, b.descricao, a.quant as quantidade, a.pcatl as preco [Ô] & _
[Ô]from balanco a, cad_produto b [Ô] & _
[Ô]where a.codp = b.codp and mesano = [ô][Ô] & TextMesAnoManutencao & [Ô][ô] order by b.descricao[Ô], con, adOpenKeyset, adLockOptimistic
With Grid
.Rows = 1[txt-color=#007100] [ô] você terá apenas um linha no flexgrid[/txt-color]
Do while Not rs.EOF
.Rows = .Rows + 1[txt-color=#007100] [ô] Aqui a cada registro ér acrescentado uma linha grid[/txt-color]
.TextMatrix(.Rows - 1, 0) = rs!codp
.TextMatrix(.Rows - 1, 1) = rs!descricao
.TextMatrix(.Rows - 1, 2) = Format(rs!QUANTIDADE, [Ô]#,##0.00[Ô])
.TextMatrix(.Rows - 1, 3) = Format(CDec(rs!Preco), [Ô]#,##0.00[Ô])
.TextMatrix(.Rows - 1, 4) = Format(CDec(.TextMatrix(.Rows - 1, 3)) * CDec(.TextMatrix(.Rows - 1, 2)), [Ô]#,##0.00[Ô])

Soma = Soma + CDbl(.TextMatrix(.Rows - 1, 4))

rs.MoveNext
Loop
End With
txt_vlrtot.Text = Soma
End Sub

GIVANILDOJTEIXE 19/04/2014 20:39:57
#437445
Public Function CarregaGrid(SQL As String, Grade As MSFlexGrid, f As Form)
Dim Soma As Double

On Error GoTo TrataErro
Grade.Clear
Grade.Rows = 0
Grade.Cols = 0

Set rs = New ADODB.Recordset

rs.Open [Ô]SELECT a.codp, b.descricao, a.quant as quantidade, a.pcatl as preco [Ô] & _
[Ô]from balanco a, cad_produto b [Ô] & _
[Ô]where a.codp = b.codp and mesano = [ô][Ô] & TextMesAnoManutencao & [Ô][ô] order by b.descricao[Ô], con, adOpenKeyset, adLockOptimistic

If rs.RecordCount = 0 Then
rs.Close
Set rs = Nothing
Exit Function
End If

rs.MoveLast
Grade.Rows = rs.RecordCount + 1
Grade.Cols = rs.Fields.Count + 1
rs.MoveFirst
Grade.FixedRows = 1
X = 1
While Not rs.EOF
For i = 1 To Grade.Cols - 1
If X = 1 Then
Grade.TextMatrix(0, i) = rs.Fields(i - 1).Name
End If
If X = Grade.Rows Then
Grade.AddItem X
End If
[ô]processe somente quando tem dados
If IsNull(rs.Fields(i - 1)) = False Then
Grade.TextMatrix(X, i) = rs.Fields(i - 1)
Else
[ô]o CAMPO vALOR PODE ESTAR NULLO
End If
Next i
rs.MoveNext
X = X + 1
Wend
rs.Close
Set rs = Nothing
Exit Function

TrataErro:
MsgBox [Ô]Erro: [Ô] & Err.Description, vbCritical
[ô]Resume

End Function
Tópico encerrado , respostas não são mais permitidas