StringGrid中使用 下拉菜单怎么弄啊
StringGrid中使用 下拉菜单怎么弄啊
帮帮忙谢谢
[解决办法]
Contorl为TWinControl 类型
if gdFocused in state then
begin
if Control <> nil then Control.Visible := false; {切换时隐藏掉}
getControl(aCol);
if Assigned(Control) then
begin
Control.SetBounds(rect.Left + grid.Left + 1, rect.Top + grid.Top + 1, rect.Right - rect.Left, rect.Bottom - rect.Top);
Control.Visible := True;
Control.SetFocus;
end;
end;
[解决办法]
在TStringGrid的格子里嵌入Combobox:
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var
R : TRect;
Org : TPoint;
begin
with TStringGrid(Sender) do
if ACol = ACol then
begin
Perform(WM_CANCELMODE, 0, 0);
R := CellRect(Acol,ARow);
Org := Self.ScreenToClient(ClientToScreen(R.TopLeft));
With Combobox1 do
begin
Setbounds(org.X, org.Y, R.Right-R.Left, Height);
ItemIndex := Items.IndexOf(Cells[ACol, ARow]);
Show;
BringTofront;
SetFocus;
//DroppedDown := True;//自动展开
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with Combobox1 do
begin
Visible := false;
Items.Clear;
Items.Add( '数据1 ');
Items.Add( '数据2 ');
ItemIndex := 0;
end;
end;
procedure TForm1.ComboBox1Exit(Sender: TObject);
begin
with TCombobox(Sender) do
begin
Hide;
if ItemIndex > = 0 then
with StringGrid1 do Cells[Col,Row] := Items[ItemIndex];
end;
end;