?怎樣在 TStringgrid中的某一列中加入一個對象如 TComboBox(50分)

  • 主题发起人 peterluo
  • 开始时间
P

peterluo

Unregistered / Unconfirmed
GUEST, unregistred user!
怎樣在 TStringgrid中的某一列中加入一個對象如 TComboBox,我想使其中一列的,內容
用下拉列表選起。
 
dfw上这个问题的回答很多,你可以搜索一下,给出一个.
http://www.delphibbs.com/delphibbs/dispq.asp?lid=786349
 
delphi自带的TstringGrid不行,要用第三方的控件。
 
我有这样的控件,很好用的,要吗,要给我分的啊
 
[:)]如不用专门控件,可用重画事件实现。
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (gdSelected in state) and (ACol=2) then
begin
ComboBox1.Top :=Rect.Top+StringGrid1.Top;
ComboBox1.Left :=Rect.Left+StringGrid1.Left;
//其他属性可自主设置
ComboBox1.Visible :=True;
end
else ComboBox1.Visible :=False;
end;
当然也可在重画过程中即时创建TComboBox,并设置属性。重画,再Free。
 
:>nbwsj
能否該列得到光標時顯示它而且按下↓時可以選起下拉列的內容?
 
不用这么麻烦用一个简单的办法就行
ComBobox1.Parent := StringGrid1;
ComBobox1.BountRect := 你想要显示的表格坐标(StringGrid1.CellRect[Row,Col])
如果你有什么问题可到http://delphi.ok100.net
 
首先放一Panel1,在此Panel1上放一SpeedButton,然后设置Panel1的AutoSize为TRUE;
Panel1的BevelOuter为bvNone,目的使这个Panel1彻底地没有留下痕迹。
再在FROM上放ComboBox1,在它的Items属性上随便放些值。

//设置StringGrid的Column要显示的字符。
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Rows[0].Add('for you want');
StringGrid1.Rows[0].Add('測試標准');
StringGrid1.Rows[0].Add('panel');
end;
//在StringGrid的自画事件中,将两个控件摆到StringGrid相应的Cells中
//Panel1.Top:=Rect.Top+StringGrid1.Top+2中的“+2”无非是使控件显示的位置更加准确。
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (gdFocused in State) then
begin
if (StringGrid1.Cells[Acol,0]='測試標准') then
begin
ComboBox1.Left:=Rect.Left+StringGrid1.Left;
ComboBox1.Top:=Rect.Top+StringGrid1.Top+3;
ComboBox1.Width:=Rect.Right-Rect.Left+2;
ComboBox1.Visible:=true;
ComboBox1.SetFocus;
ComboBox1.Text:=StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row];
end
else
ComboBox1.Visible := False;
if (StringGrid1.Cells[Acol,0]='panel') then
begin
Panel1.Left:=Rect.Right + StringGrid1.Left - Panel1.Width;
Panel1.Top:=Rect.Top+StringGrid1.Top+2;
Panel1.Height:=Rect.Bottom-Rect.Top;
Panel1.Visible:=True;
end
else
Panel1.Visible := False;
end;
end;
//将选取到的ComboBox值赋值到StringGrid相应的Cells中。
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:=ComboBox1.Items[ComboBox1.ItemIndex];
end;

//在SpeedButton1的点击事件中做你想到做的事情。

"http://www.delphibbs.com/delphibbs/dispq.asp?lid=800526"
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部