Fórum Linha selecionada em StringGrid #347056
05/10/2007
0
Olá,
O comportamento do strinGrid é diferente do DbGrid e em relção à rolagem dos itens.
Por exemplo, num DbGrid, se existirem mais registros na consulta do que o DbGrid suporta mostrar na tela e, o usuário clicar na barra de rolagem vertical, o item selecionado vai descendo ou subindo conforme a rolagem da barra.
Já no stringGrid, essa seleção automática do item seguinte ou anterior, não ocorre. Tem-se que mudar a linha através de rotina ( StringGrid.row := XX).
Quero fazer uma rotina, onde o usuário possa excluir o registro que esteja em foco (selecionado) no StringGrid. Mas esse registro tem que aparecer na tela.
Pergunto: é possível conferir se a linha selecionada no stringGrid está visível na tela? Como?
Obrigado
O comportamento do strinGrid é diferente do DbGrid e em relção à rolagem dos itens.
Por exemplo, num DbGrid, se existirem mais registros na consulta do que o DbGrid suporta mostrar na tela e, o usuário clicar na barra de rolagem vertical, o item selecionado vai descendo ou subindo conforme a rolagem da barra.
Já no stringGrid, essa seleção automática do item seguinte ou anterior, não ocorre. Tem-se que mudar a linha através de rotina ( StringGrid.row := XX).
Quero fazer uma rotina, onde o usuário possa excluir o registro que esteja em foco (selecionado) no StringGrid. Mas esse registro tem que aparecer na tela.
Pergunto: é possível conferir se a linha selecionada no stringGrid está visível na tela? Como?
Obrigado
Armindo
Curtir tópico
+ 0
Responder
Posts
05/10/2007
Rinez
Armindo:
Eu faço da seguinte forma
procedure TFMovimento.BitBtn4Click(Sender: TObject);
VAR
i,j,k:Integer;
mtotal,mtotaldesc,mtotalacres:real;
begin
if length(sg.Cells[0,1])=0 then exit;
if application.MessageBox(pchar(´Eliminar?´+#13+
´Item: ´+sg.Cells[sg.Col,sg.Row]),´Atenção´,mb_yesno)=idno then exit;
i:=sg.RowCount;
if i<3 then begin
// showmessage(´Não posso excluir Linha.Mas vou limpá-la´);
sg.Cells[7,1]:=´´;
sg.Cells[6,1]:=´´;
sg.Cells[5,1]:=´´;
sg.Cells[4,1]:=´´;
sg.Cells[3,1]:=´´;
sg.Cells[2,1]:=´´;
sg.Cells[1,1]:=´´;
sg.Cells[0,1]:=´´;
end;
if i>2 then begin
with Sg do
begin
for i:=0 to ColCount-1 do
Cells[i,Row]:=´´;
for j:=Row to RowCount-1 do
for i:=1 to ColCount-1 do
Cells[i,j]:=Cells[i,j+1];
RowCount:=RowCount-1;
end;
for i:=1 to sg.RowCount-1 do
sg.Cells[0,i]:=inttostr(i);
end; //i>2
if length(sg.Cells[0,1])<>0 then begin
mtotal:=0; mtotaldesc:=0; mtotalacres:=0;
for i:=1 to sg.RowCount-1 do begin
mtotal:=mtotal+strtoreal(sg.Cells[4,i]);
mtotaldesc:=mtotaldesc+strtoreal(sg.Cells[5,i]);
mtotalacres:=mtotalacres+strtoreal(sg.Cells[6,i]);
end;
nlsubtotal.Caption:=formatfloat(´,0.00´,mtotal);
nlsubtotaldesc.Caption:= formatfloat(´,0.00´,mtotaldesc);
nlsubtotalacres.Caption:= formatfloat(´,0.00´,mtotalacres);
ltotalgeral.Caption:=formatfloat(´,0.00´,mtotal-mtotaldesc+mtotalacres);
end ;// if length(sg.Cells[01])
if length(trim(sg.Cells[0,1]))=0 then begin
nlsubtotal.Caption:=´´;
nlsubtotaldesc.Caption:= ´´;
nlsubtotalacres.Caption:= ´´;
nltotalmov.Caption:=´´;
end;
end;
Acredito que pode usar if Stringgrid.focused para ver se esta focada.
Tenho uma funçao para transformar uma string do formato 4.000,00
para float quando quero gravar. (strtoreal).
Coloque aqui se lhe ajudou.
Eu faço da seguinte forma
procedure TFMovimento.BitBtn4Click(Sender: TObject);
VAR
i,j,k:Integer;
mtotal,mtotaldesc,mtotalacres:real;
begin
if length(sg.Cells[0,1])=0 then exit;
if application.MessageBox(pchar(´Eliminar?´+#13+
´Item: ´+sg.Cells[sg.Col,sg.Row]),´Atenção´,mb_yesno)=idno then exit;
i:=sg.RowCount;
if i<3 then begin
// showmessage(´Não posso excluir Linha.Mas vou limpá-la´);
sg.Cells[7,1]:=´´;
sg.Cells[6,1]:=´´;
sg.Cells[5,1]:=´´;
sg.Cells[4,1]:=´´;
sg.Cells[3,1]:=´´;
sg.Cells[2,1]:=´´;
sg.Cells[1,1]:=´´;
sg.Cells[0,1]:=´´;
end;
if i>2 then begin
with Sg do
begin
for i:=0 to ColCount-1 do
Cells[i,Row]:=´´;
for j:=Row to RowCount-1 do
for i:=1 to ColCount-1 do
Cells[i,j]:=Cells[i,j+1];
RowCount:=RowCount-1;
end;
for i:=1 to sg.RowCount-1 do
sg.Cells[0,i]:=inttostr(i);
end; //i>2
if length(sg.Cells[0,1])<>0 then begin
mtotal:=0; mtotaldesc:=0; mtotalacres:=0;
for i:=1 to sg.RowCount-1 do begin
mtotal:=mtotal+strtoreal(sg.Cells[4,i]);
mtotaldesc:=mtotaldesc+strtoreal(sg.Cells[5,i]);
mtotalacres:=mtotalacres+strtoreal(sg.Cells[6,i]);
end;
nlsubtotal.Caption:=formatfloat(´,0.00´,mtotal);
nlsubtotaldesc.Caption:= formatfloat(´,0.00´,mtotaldesc);
nlsubtotalacres.Caption:= formatfloat(´,0.00´,mtotalacres);
ltotalgeral.Caption:=formatfloat(´,0.00´,mtotal-mtotaldesc+mtotalacres);
end ;// if length(sg.Cells[01])
if length(trim(sg.Cells[0,1]))=0 then begin
nlsubtotal.Caption:=´´;
nlsubtotaldesc.Caption:= ´´;
nlsubtotalacres.Caption:= ´´;
nltotalmov.Caption:=´´;
end;
end;
Acredito que pode usar if Stringgrid.focused para ver se esta focada.
Tenho uma funçao para transformar uma string do formato 4.000,00
para float quando quero gravar. (strtoreal).
Coloque aqui se lhe ajudou.
Responder
Gostei + 0
05/10/2007
Armindo
Amigo, obrigado pela resposta, mas o .focused não funciona, pois preciso executar essa rotina quando o usuário digitar algo em outro Edit. Então, o .focused sempre vai ser false.
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)