StringGrid - colocando um combo dentro de um celula |
Top Previous Next |
|
//Colocar uma combo numa celula da string grid
procedure TForm1.FormCreate(Sender: TObject); begin // Ajusta a altura do ComboBox com a altura da linha do StringGrid} StringGrid1.DefaultRowHeight := ComboBox1.Height; // Esconde o ComboBox ComboBox1.Visible := False; end;
procedure TForm1.ComboBox1Change(Sender: TObject); begin // quando troca o conteudo da combo, deve-se transferir o text de uma para outra StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] := ComboBox1.Items[ComboBox1.ItemIndex]; ComboBox1.Visible := False; StringGrid1.SetFocus; end;
procedure TForm1.ComboBox1Exit(Sender: TObject); begin // quando sai da combo tambem... StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] := ComboBox1.Items[ComboBox1.ItemIndex]; ComboBox1.Visible := False; StringGrid1.SetFocus; end;
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); var R: TRect; begin // Só mostra a combo se a coluna for a 3... if ((ACol = 3) 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; ComboBox1.Left := R.Left + 1; ComboBox1.Top := R.Top + 1; ComboBox1.Width := (R.Right + 1) - R.Left; ComboBox1.Height := (R.Bottom + 1) - R.Top; ComboBox1.Visible:= True; ComboBox1.SetFocus; end; CanSelect := True; end; |