如何在stringgrid中嵌入combobox,并且combobx的值可以在页面初始化时动态加入(50分)

  • 主题发起人 主题发起人 fishinsea
  • 开始时间 开始时间
F

fishinsea

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在stringgrid中嵌入combobox,并且combobx的值可以在页面初始化时动态加入的 <br>举例:一个窗体中有stringgrid1、combobox1组件,我想在stringgrid1的第二列当鼠标获得焦点是显示下拉菜单, <br>也就是把combobox1的嵌入进去,然后把选择的值再传给单元格,当该单元个失去焦点时,不显示combobx1,combobx1的内容是在窗体初始化时动态导入的,导入的是数据库中某个表的内容,我不想用第三方组件,请教高手如何实现,麻烦给点代码,越详细越好,谢谢了
 
以 Cells[1,2] 嵌入 ComboBox1 为例:<br>procedure TForm1.ComboBox1Change(Sender: TObject);<br>begin<br>&nbsp; StringGrid1.Cells[1,2]:=ComboBox1.Text;<br>&nbsp; caption:=ComboBox1.Text;<br>end;<br><br>procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;<br>&nbsp; Rect: TRect; State: TGridDrawState);<br>var<br>&nbsp; h: integer;<br>begin<br>&nbsp; h:=(StringGrid1.DefaultRowHeight - ComboBox1.Height) div 2;<br><br>&nbsp; if gdFocused in state then<br>&nbsp; begin<br>&nbsp; &nbsp; if ComboBox1 &lt;&gt; nil then ComboBox1.Visible := false;<br>&nbsp; &nbsp; if Assigned(ComboBox1) and (ACol = 1) and (ARow = 2) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ComboBox1.SetBounds(rect.Left + StringGrid1.Left + 1, rect.Top + StringGrid1.Top + h + 2, rect.Right - rect.Left, ComboBox1.Height);<br>&nbsp; &nbsp; &nbsp; ComboBox1.Visible := True;<br>&nbsp; &nbsp; &nbsp; ComboBox1.SetFocus;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;
 
后退
顶部