DBGrid..Transferencia de dados
[img][url=http://imageshack.us][img=http://img138.imageshack.us/img138/6682/imagem7bz.jpg][/url][/img]
presciso tranferir os dados do primeiro formulário para o segundo para peder formula cálculos...
no código abaixo tenho uma função de como deletar os ítens selecionados...táves tem como adaptar esta função para o que estou prescisando...
var i: integer;
begin
with wwdbgrid1, wwdbgrid1.datasource.dataset do begin
DisableControls; { Disable controls to improve performance }
for i:= 0 to SelectedList.Count-1 do begin
GotoBookmark(SelectedList.items[i]);
Freebookmark(SelectedList.items[i]);
Delete; { Delete Record }
end;
SelectedList.clear; { Clear selected record list since they are all deleted}
EnableControls; { Reenable controls }
end;
Vamo ver se temos mais sorte desta vez... valw...t+
Gigatel
Respostas
Gigatel
11/09/2005
[img][URL=http://imageshack.us][img:0c0f73b15e]http://img138.imageshack.us/img138/6682/imagem7bz.jpg[/img:0c0f73b15e][/URL][/img]
Gigatel
11/09/2005
Gigatel
11/09/2005
Michelli88
11/09/2005
Gigatel
11/09/2005
{
Na cláusula uses coloque a unit "Clipbrd"
Coloque o código abaixo, por exemplo, no evento onClick de um botão
}
var Linhas: TStringList;
i, posicao: integer;
s: string;
begin
Linhas := TStringList.Create;
Clipboard.Open;
try
with DBGrid1 do
begin
DataSource.DataSet.DisableControls;
Posicao := DataSource.DataSet.RecNo;
DataSource.DataSet.First;
while not DataSource.DataSet.Eof do
begin
s := ´´;
for i := 0 to Columns.Count - 1 do
begin
if i > 0 then s := s + #9; // Tabulação
s := s + Columns.Items[i].Field.Text;
end;
Linhas.Add(s);
DataSource.DataSet.Next;
end;
DataSource.DataSet.RecNo := Posicao;
DataSource.DataSet.EnableControls;
end;
Clipboard.SetTextBuf(Pointer(Linhas.Text));
finally
Linhas.Free;
Clipboard.Close;
end;
Vamo ver né ?
Michelli88
11/09/2005
Veja na declaração o tipo que é ou da unit que vc ta adicionando na clausula uses...
Gigatel
11/09/2005
Vc notou a figua acima ?...eu presciso que os mesmos dados da parte de baixo da figura que estão selecionados ou parte deles ( como descrissão e valor ) vão para o segundo form, para o usuário ficar sabendo o que selecionou e tbm ser realizados cálculos somente dos ítens do segundo form..
Michelli88
11/09/2005
... vc poderia armazenar os codigos dos registros selecionados num StringGrid e enviar via parametro... vc passa essa lista de códigos, e a partir da lista vc consulta o banco novamente e carrega no grid...
A procedure ficaria assim:
procedure passarLista(Lista: Stringgrid); begin for i:= 0 to SelectedList.Count-1 do begin // aqui vc testa se o item ta checado e armazena na stringgrid: if ... then Lista[i]:= Codigo; end; end;
espero que ajude..
Gigatel
11/09/2005
procedure passarLista(Lista: Stringgrid); begin for i:= 0 to SelectedList.Count-1 do begin // aqui vc testa se o item ta checado e armazena na stringgrid: if ... then Lista[i]:= Codigo; end; end;
Michelli88
11/09/2005
Gigatel
11/09/2005
Ta aí...más eu num sei fazer isto...
eu tenho uma tabela ( interbase )que se chama CONTAS_RECEBER
Minha IBQuery se chama BD_CONT_REC.
os campos que uso para visualizar são estes..
GS_COR_CODIGO
GS_COR_NOME
GS_COR_DESCRICAO
GS_COR_CODIGO_DATA_VENC
num faço nem idéia de como transferir estes dados...más ver o q dá..valeu pela disponibilidade..
Michelli88
11/09/2005
pelo que deu pra entender no código da função de deletar, ja existe uma lista que eh a dos itens selecionados.. Deve haver um jeito de acessar esses dados, aquele eh o um grid comum? Parece q vc disse q comprou um componente?
Entao, no proprio grid que vc tem ai, vc vai pegar o codigo de todos q foram selecionados e adicionar na Stringlist.
var Lista : Stringlist; Lista[i]:= QueryGridCodigo.AsString; //adiciona os item na Stringlist
Gigatel
11/09/2005
GotoBookmark(SelectedList.items[i]);
De fato eu uso um componente mesmo...comprei a licença de um colega, o componete se chama ...INFOPOWER.. parece ser bom este componete tem várias outras funções....
Gigatel
11/09/2005
[Error] Unit18.pas(811): Undeclared identifier: ´Stringlist´
Michelli88
11/09/2005
Gigatel
11/09/2005
var
i: integer;
begin
with wwdbgrid1, wwdbgrid1.datasource.dataset do begin
DisableControls; { Disable controls to improve performance }
for i:= 0 to SelectedList.Count-1 do begin
GotoBookmark(SelectedList.items[i]);
Freebookmark(SelectedList.items[i]);
StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:= wwdbgrid1.SelectedList;
end;
SelectedList.clear; { Clear selected record list since they are all deleted}
EnableControls;
end;
más deu este erro..
[Error] Unit18.pas(818): Incompatible types: ´String´ and ´TList´
na luta......
Michelli88
11/09/2005
var
i: integer;
begin
with wwdbgrid1, wwdbgrid1.datasource.dataset do begin
DisableControls; { Disable controls to improve performance }
for i:= 0 to SelectedList.Count-1 do begin
GotoBookmark(SelectedList.items[i]);
Freebookmark(SelectedList.items[i]);
StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:= wwdbgrid1.SelectedList[i];
end;
SelectedList.clear; { Clear selected record list since they are all deleted}
EnableControls;
end; acho q eh isso... ;-)
Emerson Nascimento
11/09/2005
var
i: integer;
begin
with wwdbgrid1, wwdbgrid1.datasource.dataset do
begin
DisableControls; { Disable controls to improve performance }
{numero de itens escolhidos mais uma linha para os titulos}
StringGrid1.RowCount := SelectedList.Count + 1;
{varre os itens selecionados e os adiciona na grade}
for i:= 0 to SelectedList.Count-1 do
begin
GotoBookmark(SelectedList.items[i]);
Freebookmark(SelectedList.items[i]);
StringGrid1.Cells[0,i+1] := wwdbgrid1.dataset.fieldbyname(´codigo´).asstring;
StringGrid1.Cells[1,i+1] := wwdbgrid1.dataset.fieldbyname(´descricao´).asstring;
end;
// SelectedList.clear; { Clear selected record list since they are all deleted}
EnableControls;
end;Gigatel
11/09/2005
[Error] Unit18.pas(825): Undeclared identifier: ´dataset´
aí mudei o código para isto..
StringGrid1.Cells[1,i+1] := wwdbgrid1.DataSource.fieldbyname(´descricao´).asstring;
O seu código depois de modificado deu este erros ao executar ( depois de copilado ).. Nenhum argumneto para o formato ¬s´
o que seria ?
Gigatel
11/09/2005
var
i: integer;
begin
with wwdbgrid1, wwdbgrid1.datasource.dataset do begin
DisableControls; { Disable controls to improve performance }
for i:= 0 to SelectedList.Count-1 do begin
GotoBookmark(SelectedList.items[i]);
Freebookmark(SelectedList.items[i]);
StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:= wwdbgrid1.SelectedList[i];
end;
SelectedList.clear; { Clear selected record list since they are all deleted}
EnableControls;
end; O seu código deu este erro...
[Error] Unit18.pas(842): Incompatible types: ´String´ and ´Pointer´
o legal é que tem outro colaborador para ajudar tbm..vlw..
Michelli88
11/09/2005
StringGrid1.Cells[1,i+1] := wwdbgrid1.DataSource.dataset.fieldbyname(´descricao´).asstring;
Colega, vai tentando ai...
Emerson Nascimento
11/09/2005
var
i: integer;
begin
with wwdbgrid1, wwdbgrid1.datasource.dataset do
begin
DisableControls; { Disable controls to improve performance }
{numero de itens escolhidos mais uma linha para os titulos}
StringGrid1.RowCount := SelectedList.Count + 1;
{varre os itens selecionados e os adiciona na grade}
for i:= 0 to SelectedList.Count-1 do
begin
GotoBookmark(SelectedList.items[i]);
Freebookmark(SelectedList.items[i]);
StringGrid1.Cells[0,i+1] := wwdbgrid1.datasource.dataset.fieldbyname(´codigo´).asstring;
StringGrid1.Cells[1,i+1] := wwdbgrid1.datasource.dataset.fieldbyname(´descricao´).asstring;
end;
// SelectedList.clear; { Clear selected record list since they are all deleted}
EnableControls;
end;Gigatel
11/09/2005
var i: integer; begin with wwdbgrid1, wwdbgrid1.datasource.dataset do begin DisableControls; for i:= 0 to SelectedList.Count-1 do begin GotoBookmark(SelectedList.items[i]); Freebookmark(SelectedList.items[i]); StringGrid1.Cells[0,i+1] := wwdbgrid1.DataSource.dataset.fieldbyname(´GS_COR_CODIGO´).asstring; StringGrid1.Cells[1,i+1] := wwdbgrid1.DataSource.dataset.fieldbyname(´GS_COR_DESCRICAO´).asstring; StringGrid1.Cells[3,i+1] := wwdbgrid1.DataSource.dataset.fieldbyname(´GS_COR_VALOR_PARCELA´).asstring; StringGrid1.Cells[2,i+1] := wwdbgrid1.DataSource.dataset.fieldbyname(´GS_COR_DATA_VENC´).asstring; StringGrid1.Cells[4,i+1] := wwdbgrid1.DataSource.dataset.fieldbyname(´GS_COR_DATRASO´).asstring; end; SelectedList.clear; EnableControls; end;
Ponto para as meninas...Rsss, agora voltando ao papo sério como faço para o StringGrid1 ficar parecido com o dbgrid...tipo...presciso saber como colocar um tamanho nas larguas nos grids e nomes nas artes escura...iguál ao desenho...
[img][URL=http://imageshack.us][img:3694003423]http://img122.imageshack.us/img122/1247/imagem9hq.jpg[/img:3694003423][/URL][/img]
e aproveitando o frete....como seria o lance dos cálculos... na quarta grade tem uns valores ...como eu faria para capturar os números para os cálculos?..pera..vamos por parte né ?....vlw..msm...
Michelli88
11/09/2005
O Titulo é a linha 0.
larguras e alturas...
Self.tabela.ColWidths[20]:=150; Self.tabela.RowHeights[10]:=5;
e pra acessar os dados, eh da mesma forma que vc colocou la...
dado:= StringGrid.Cells[coluna,linha];
Gigatel
11/09/2005
StringGrid1.Cells[0,i+1] := wwdbgrid1.DataSource.dataset.fieldbyname(´GS_COR_CODIGO´).asstring;
e tem como fazer de cada coluna separado ?..
Michelli88
11/09/2005
Na hora q criar a tabela vc ja seta todos os tamanhos:
pode ser assim:
StringGrid1.ColWidths[1]:=150; StringGrid1.ColWidths[2]:=200; StringGrid1.ColWidths[3]:=50; StringGrid1.ColWidths[4]:=100;
os numeros 1,2,3 e 4 sao as colunas...
nao tem nada a ver com a linha q vc perguntou... eh separado! :idea:
Gigatel
11/09/2005
Michelli88
11/09/2005
:roll:
Gigatel
11/09/2005
é o seguinte tenho 20 registros no DBGRID..seleciono 8 itens o stringgrid deveria gerar as 8 linhas ou naum...
Michelli88
11/09/2005
Emerson Nascimento
11/09/2005
{numero de itens escolhidos mais uma linha para os titulos}
[b:02ec05a2ea][color=blue:02ec05a2ea]StringGrid1.RowCount := SelectedList.Count + 1;[/color:02ec05a2ea][/b:02ec05a2ea] [b:02ec05a2ea]<-- essa linha faz o que vc quer[/b:02ec05a2ea]
{varre os itens selecionados e os adiciona na grade}
for i:= 0 to SelectedList.Count-1 do
begin
GotoBookmark(SelectedList.items[i]);
Freebookmark(SelectedList.items[i]);
{...}
Gigatel
11/09/2005
Ok funcionou perfeito valew...Más qkele lance do cabeçalho num entendí como faz ( I Descrição I Vencimento I Atraso ) como faz para coloca -los..Tá ficando show de bola...valw...
Emerson Nascimento
11/09/2005
var
i: integer;
begin
with wwdbgrid1, wwdbgrid1.datasource.dataset do
begin
DisableControls; { Desabilita os controles para adicionar performance }
{número de itens escolhidos mais uma linha para os titulos}
StringGrid1.RowCount := SelectedList.Count + 1;
{o número de colunas na grade deve ser pré-definido então
vamos apenas colocar as mesmas larguras e os mesmos títulos}
for i := 0 to wwdbgrid1.Columns.Count-1 do
begin
StringGrid1.ColWidths[i] := wwdbgrid1.Columns[0].Width;
StringGrid1.Cells[i,0] := wwdbgrid1.Columns[0].Title.Caption;
end;
{varre os itens selecionados e os adiciona na grade}
for i:= 0 to SelectedList.Count-1 do
begin
GotoBookmark(SelectedList.items[i]);
Freebookmark(SelectedList.items[i]);
StringGrid1.Cells[0,i+1] := fieldbyname(´GS_COR_CODIGO´).asstring;
StringGrid1.Cells[1,i+1] := fieldbyname(´GS_COR_DESCRICAO´).asstring;
StringGrid1.Cells[3,i+1] := fieldbyname(´GS_COR_VALOR_PARCELA´).asstring;
StringGrid1.Cells[2,i+1] := fieldbyname(´GS_COR_DATA_VENC´).asstring;
StringGrid1.Cells[4,i+1] := fieldbyname(´GS_COR_DATRASO´).asstring;
end;
SelectedList.clear; { Clear selected record list since they are all deleted}
EnableControls;
end;Gigatel
11/09/2005
procedure T_FORM_CR_NAV.TSG ; var i: integer; begin with wwdbgrid1, wwdbgrid1.datasource.dataset do begin DisableControls; _FORM_CR_MS.StringGrid1.RowCount := SelectedList.Count + 1; for i:= 0 to SelectedList.Count-1 do begin GotoBookmark(SelectedList.items[i]); Freebookmark(SelectedList.items[i]); _FORM_CR_MS.StringGrid1.Cells[0,0] := ´Código´; _FORM_CR_MS.StringGrid1.Cells[1,0] := ´Descrição´; _FORM_CR_MS.StringGrid1.Cells[2,0] := ´Vencimento´; _FORM_CR_MS.StringGrid1.Cells[3,0] := ´Valor´; _FORM_CR_MS.StringGrid1.Cells[4,0] := ´Atraso´; _FORM_CR_MS.StringGrid1.Cells[0,i+1] := wwdbgrid1.DataSource.dataset.fieldbyname(´GS_COR_CODIGO´).asstring; _FORM_CR_MS.StringGrid1.ColWidths[1]:=240; _FORM_CR_MS.StringGrid1.Cells[1,i+1] := wwdbgrid1.DataSource.dataset.fieldbyname(´GS_COR_DESCRICAO´).asstring; _FORM_CR_MS.StringGrid1.Cells[3,i+1] := wwdbgrid1.DataSource.dataset.fieldbyname(´GS_COR_VALOR_PARCELA´).asstring; _FORM_CR_MS.StringGrid1.Cells[2,i+1] := wwdbgrid1.DataSource.dataset.fieldbyname(´GS_COR_DATA_VENC´).asstring; _FORM_CR_MS.StringGrid1.Cells[4,i+1] := wwdbgrid1.DataSource.dataset.fieldbyname(´GS_COR_DATRASO´).asstring; _FORM_CR_MS.StringGrid1.ColWidths[4]:=40; end; SelectedList.clear; EnableControls; end; end;
este _FORM_CR_MS é o form onde fica o Stringgrid....
Aí ficou assim...Más já estou me deparando com outro problema..este código abaixo é o responsável em deletar ítens selecionados, eu vou prescisar de deletar os registros depois de calculados os valores e etc..pois estaria dando baixa na nota da pessoa...como proceder?... tem alguma idéa ?
var i: integer;
begin
with wwdbgrid1, wwdbgrid1.datasource.dataset do begin
DisableControls; { Disable controls to improve performance }
for i:= 0 to SelectedList.Count-1 do begin
GotoBookmark(SelectedList.items[i]);
Freebookmark(SelectedList.items[i]);
Delete; { Delete Record }
end;
SelectedList.clear; { Clear selected record list since they are all deleted}
EnableControls; { Reenable controls }
end;
é que depois que é gerado o form que tem o stringgrid os íten são desmarcados...Problemas e problemas...más estamos no caminho...vlw
Emerson Nascimento
11/09/2005
procedure T_FORM_CR_NAV.TSG ; var i: integer; begin with wwdbgrid1, wwdbgrid1.datasource.dataset do begin DisableControls; _FORM_CR_MS.StringGrid1.RowCount := SelectedList.Count + 1; _FORM_CR_MS.StringGrid1.Cells[0,0] := ´Código´; _FORM_CR_MS.StringGrid1.Cells[1,0] := ´Descrição´; _FORM_CR_MS.StringGrid1.Cells[2,0] := ´Vencimento´; _FORM_CR_MS.StringGrid1.Cells[3,0] := ´Valor´; _FORM_CR_MS.StringGrid1.Cells[4,0] := ´Atraso´; _FORM_CR_MS.StringGrid1.ColWidths[1]:=240; _FORM_CR_MS.StringGrid1.ColWidths[4]:=40; for i:= 0 to SelectedList.Count-1 do begin GotoBookmark(SelectedList.items[i]); Freebookmark(SelectedList.items[i]); _FORM_CR_MS.StringGrid1.Cells[0,i+1] := fieldbyname(´GS_COR_CODIGO´).asstring; _FORM_CR_MS.StringGrid1.Cells[1,i+1] := fieldbyname(´GS_COR_DESCRICAO´).asstring; _FORM_CR_MS.StringGrid1.Cells[3,i+1] := fieldbyname(´GS_COR_VALOR_PARCELA´).asstring; _FORM_CR_MS.StringGrid1.Cells[2,i+1] := fieldbyname(´GS_COR_DATA_VENC´).asstring; _FORM_CR_MS.StringGrid1.Cells[4,i+1] := fieldbyname(´GS_COR_DATRASO´).asstring; end; SelectedList.clear; EnableControls; end; end;
Gigatel
11/09/2005
Gigatel
11/09/2005
var i: integer;
begin
with _FORM_CR_NAV.wwdbgrid1, _FORM_CR_NAV.wwdbgrid1.datasource.dataset do begin
for i:= 0 to SelectedList.Count-1 do begin
GotoBookmark(SelectedList.items[i]);
Freebookmark(SelectedList.items[i]);
Delete; { Delete Record }
end;
SelectedList.clear; { Clear selected record list since they are all deleted}
EnableControls; { Reenable controls }
end;
// Close;
Funciona até chegar no CLOSE... aí dá um erro..
[img][URL=http://imageshack.us][img:e88c40c8da]http://img281.imageshack.us/img281/1220/imagem9gc.jpg[/img:e88c40c8da][/URL][/img]
Cabreu.jr
11/09/2005
vc não precisa de stringlist,stringgrid ou nada deste tipo,use a grid mesmo.
Faz o seguinte := crie uma variavel do tipo string e naquele looping que repetiram tantas vezes (tb;saiu do help do infopower) pegue o valor da chave primária e jogue na variavel acrescentando uma virgula no final.
Depois do looping acrescente o seguinte codigo na SQL da query de grid 2:
´where codctareceber in ( ´ + variavelstring + ´);
quando vc abrir a query vai trazer somente os registros previamente selecionados.
Qualquer dúvida ou problema,responda aqui que te passo o código completo. Sempre faço assim e fica muito rápido e limpo.
Gigatel
11/09/2005
Gigatel
11/09/2005
Gigatel
11/09/2005
Más aki...dá para fazer sem ter um table interligado ao Wdbgrid ? coloca um código de como seria isto...estou quebrando a cabeça tem uns dias..e estou prescisando agilizar isto...vlw..t+ no aguardo...
Cabreu.jr
11/09/2005
[b:35262214ad]tabela[/b:35262214ad]CtaRecTeste -> Campos:
CodcatRec,
Cliente,
DataVencto,
Valor,
DataPagto,
ValorPago,
Juros,
Desconto
------------------------------------------------------
[b:35262214ad]form1[/b:35262214ad]
um Botão com o caption ´receber´;
uma wwdbgrid com [i:35262214ad]multiselect = true[/i:35262214ad];
uma wwquery com a seguinte SQL : ´SELECT * FROM CtaRecTeste WHERE DATAPAGTO IS NULL´ ;
um datasource para ligar a grid a query.
no evento onclick do botão:
[color=red:35262214ad]procedure TForm1.Button1Click(Sender: TObject);
var
I : integer;
Titulos : string;
begin
Titulos := ´´;
if Grid1.SelectedList.Count = 0 then
ShowMessage(´Selecione ao menos um registro´)
else
begin
for I := 0 to Grid1.SelectedList.Count - 1 do
begin
qryForm1.GotoBookmark(Grid1.SelectedList.items[i]);
//Pega os valores da chave primária
Titulos := Titulos + QuotedStr(qryForm1CodCtaRec.asstring);
if I < (Grid1.SelectedList.Count - 1) then
Titulos := Titulos + ´,´;
end;
//Muda a SQL de qryform2 para trazer somente os titulos selecionados
Form2.qryForm2.close;
Form2.qryForm2.SQL.Text := ´SELECT * FROM CtaRecTeste´ +
´ WHERE CodCtaRec IN ( ´ + Titulos + ´)´;
Form2.qryForm2.Open;
Form2.ShowModal;
//reabre qryform1 que não irá mais trazer os títulos baixados
qryForm1.Close;
qryForm1.open;
end;
end;[/color:35262214ad]
---------------------------------------------------------------------
[b:35262214ad]form2[/b:35262214ad]
um Botão com o caption ´receber´;
uma wwdbgrid;
uma wwquery;
dbedits paa inserir os valores dos juros e desconto
um datasource para ligar a grid a query.
no evento onclick do botao:
[color=red:35262214ad] procedure TForm2.Button1Click(Sender: TObject);
begin
qryForm2.Edit;
qryForm2ValorPago.value := qryForm2Valor.value;
qryForm2DataPagto.Value := date;
qryForm2.Post;
end;[/color:35262214ad]
-----------------------------------------------------------------------
Gigatel
11/09/2005
Gigatel
11/09/2005
Gigatel
11/09/2005
Cabreu.jr
11/09/2005