看看这个 在dbgrid下的加成checkbox
procedure Tfrmsysset.DBGrid1DrawDataCell(Sender: TObject;
const Rect: TRect; Field: TField; State: TGridDrawState);
begin
if not (gdFocused in state) then exit
else
begin
with dbcheckbox1 do
if (dbgrid1.SelectedField.FieldName=datafield) then
begin
left:=Rect.Left+dbgrid1.Left;
top:=rect.Top+dbgrid1.Top;
width:=rect.Right-rect.Left;
height:=rect.Bottom-rect.Top;
visible:=true;
end;
end;
end;
procedure Tfgsspdbdform.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var n,s:integer;
begin
if x<25 then
begin
n:=stringgrid1.Row;
stringgrid1.Cells[0,n]:=inttostr(n+1);
end;
combobox5.Visible :=false;
combobox10.Visible :=false;
combobox7.Visible :=false;
combobox6.Visible :=false;
combobox8.Visible :=false;
if (x>25) and (x<77) then
begin
combobox5.Visible :=true;
combobox10.Visible :=false;
combobox7.Visible :=false;
combobox6.Visible :=false;
combobox8.Visible :=false;
end;
if (x>77) and (x<148) then
begin
combobox10.Visible :=true;
combobox6.Visible :=false;
combobox7.Visible :=false;
combobox8.Visible :=false;
combobox5.Visible :=false;
end;
if (x>148) and (x<220) then
begin
combobox10.Visible :=false;
combobox6.Visible :=true;
combobox5.Visible :=false;
combobox7.Visible :=false;
combobox8.Visible :=false;
end;
if (x>221) and (x<378) then
begin
combobox5.Visible :=false;
combobox8.Visible :=true;
combobox7.Visible :=false;
combobox6.Visible :=false;
combobox10.Visible :=false;
end;
if (x>637) and (x<676) then
begin
combobox10.Visible :=false;
combobox5.Visible :=false;
combobox6.Visible :=false;
combobox7.Visible :=true;
combobox8.Visible :=false;
end;
s:=y div 22 ;
combobox5.Top :=172+s*22;
combobox6.top:=combobox5.Top ;
combobox7.Top :=combobox5.Top ;
combobox8.Top :=combobox5.Top ;
combobox10.Top :=combobox5.top;
end;
------
procedure Tfgsspdbdform.ComboBox5Exit(Sender: TObject);
var n:integer;
begin
n:=stringgrid1.row;
stringgrid1.Cells[1,n]:=combobox5.Text ;
combobox5.Visible :=false;
end;
procedure Tfgsspdbdform.ComboBox6Exit(Sender: TObject);
var n:integer;
begin
n:=stringgrid1.row;
if combobox6.text<>'' then stringgrid1.Cells[3,n]:=combobox6.Text ;
combobox6.text:='';
combobox6.Visible :=false;
end;
procedure Tfgsspdbdform.ComboBox7Exit(Sender: TObject);
var n:integer;
begin
n:=stringgrid1.row;
if combobox7.text<>'' then stringgrid1.Cells[10,n]:=combobox7.Text ;
combobox7.Visible :=false;
end;
//设置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;