Fórum Delphi - ComboBox em StringGrid #607365
08/01/2020
0
// Evento OnCreate do Form
{ Ajusta a altura do ComboBox com a altura da linha do StringGrid}
StringGrid1.DefaultRowHeight := cmbInsc.Height;
cmbInsc.Visible := False;
// Evento OnChange do componente ComboBox
StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] := cmbInsc.Items[cmbInsc.ItemIndex];
cmbInsc.Visible := False;
StringGrid1.SetFocus;
// Evento OnExit do componente ComboBox
StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] := cmbInsc.Items[cmbInsc.ItemIndex];
cmbInsc.Visible := False;
StringGrid1.SetFocus;
// Evento OnSelectCell do componente StringGrid
begin
if ((ACol = 4) AND (ARow <> 0)) then
begin
R := StringGrid1.CellRect(ACol, ARow);
R.Left := R.Left + StringGrid1.Left;
R.Right := R.Right + StringGrid1.Left;
R.Top := R.Top + StringGrid1.Top;
R.Bottom := R.Bottom + StringGrid1.Top;
cmbInsc.Left := R.Left + 1;
cmbInsc.Top := R.Top + 1;
cmbInsc.Width := (R.Right + 1) - R.Left;
cmbInsc.Height := (R.Bottom + 1) - R.Top;
cmbInsc.Visible := True;
cmbInsc.SetFocus;
cmbInsc.Text := StringGrid1.Cells[Acol,Arow];
end;
CanSelect := True;
end;
Porém, dessa forma sempre que preencho a célula com o combo e clico em outra, ele repete a informação.. Alguém saberia como fazer para não repetir os dados?
Obrigado desde já!
Nomad
Curtir tópico
+ 1Posts
09/01/2020
Nomad
// Evento OnCreate do Form
{ Ajusta a altura do ComboBox com a altura da linha do StringGrid}
StringGrid1.DefaultRowHeight := cmbInsc.Height;
cmbInsc.Visible := False;
// Evento OnChange do componente ComboBox
StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] := cmbInsc.Items[cmbInsc.ItemIndex];
cmbInsc.Visible := False;
StringGrid1.SetFocus;
// Evento OnExit do componente ComboBox
StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] := cmbInsc.Items[cmbInsc.ItemIndex];
cmbInsc.Visible := False;
StringGrid1.SetFocus;
// Evento OnSelectCell do componente StringGrid
begin
if ((ACol = 4) AND (ARow <> 0)) then
begin
R := StringGrid1.CellRect(ACol, ARow);
R.Left := R.Left + StringGrid1.Left;
R.Right := R.Right + StringGrid1.Left;
R.Top := R.Top + StringGrid1.Top;
R.Bottom := R.Bottom + StringGrid1.Top;
cmbInsc.Left := R.Left + 1;
cmbInsc.Top := R.Top + 1;
cmbInsc.Width := (R.Right + 1) - R.Left;
cmbInsc.Height := (R.Bottom + 1) - R.Top;
cmbInsc.Visible := True;
cmbInsc.SetFocus;
cmbInsc.Text := StringGrid1.Cells[Acol,Arow];
end;
CanSelect := True;
end;
Porém, dessa forma sempre que preencho a célula com o combo e clico em outra, ele repete a informação.. Alguém saberia como fazer para não repetir os dados?
Obrigado desde já!
Up!
Gostei + 0
10/01/2020
Manoel Junior
Gostei + 0
13/01/2020
Nomad
Cara, tentei dessa forma... Mas o problema de fazer no OnSelect, é que limpa o conteúdo do próprio combobox.
Gostei + 0
15/01/2020
Nomad
Cara, tentei dessa forma... Mas o problema de fazer no OnSelect, é que limpa o conteúdo do próprio combobox.
Up
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)