关于在STRINGGRID中的cell中画TDBEIDT控件的问题,高手请进!有原程序

fjy351 2001-11-27 04:35:27
我在FORMSHOW中写了这样的语句:
procedure TForm1.FormShow(Sender: TObject);
var i,j:integer;
begin
table1.Close;
table2.Close;
if table1.Active=false then
table1.Active:=true;
table2.open;
for j:=0 to table1.RecordCount-1 do
begin
for i:=0 to table1.fieldCount-1 do
begin
if table1.Fields[i].FieldName='BMBH' then
begin
StringGrid1.Cells[i,0]:='BMMC';
stringgrid1.Cells[i,j+1]:=table2.fieldbyname('bmmc').AsString;
continue;
end;
StringGrid1.Cells[i,0]:=table1.Fields[i].fieldname;
stringgrid1.Cells[i,j+1]:=table1.Fields[i].AsString;
end;
table1.Next;
end;
StringGrid1.ColCount:=table1.FieldCount;
StringGrid1.RowCount:=table1.recordcount+1;
while not table2.Eof do
begin
DBComboBox1.Items.Add(table2.fieldbyname('bmmc').asstring);
table2.Next;
end;
DBEdit1.Visible:=false;
DBComboBox1.Visible:=false;
end;
在StringGrid1DrawCell中写了这样的语句:
if (gdfocused in state) then
begin

if stringgrid1.Cells[acol,0]<>'BMMC' then
begin
DBEdit1.DataField:=stringgrid1.Cells[acol,0];
DBEdit1.text:=stringgrid1.Cells[acol,arow];
DBEdit1.Left := Rect.Left + stringgrid1.Left;
DBEdit1.Top := Rect.Top + stringgrid1.top;
DBEdit1.Width := Rect.Right - Rect.Left;
DBEdit1.Height:=DBEdit1.Height;
DBEdit1.Visible := True;
DBEdit1.SetFocus;
end;
if stringgrid1.Cells[acol,0]='BMMC' then
begin
DBComboBox1.DataField:='BMMC';
DBComboBox1.text:=stringgrid1.cells[acol,arow];
DBComboBox1.Left := Rect.Left + stringgrid1.Left;
DBComboBox1.Top := Rect.Top + stringgrid1.top;
DBComboBox1.Width := Rect.Right - Rect.Left;
DBComboBox1.Height:=DBComboBox1.Height;
DBComboBox1.Visible := True;
DBComboBox1.SetFocus;
end;

end
else
begin
DBEdit1.Visible:=false;
DBComboBox1.Visible:=false;
end;
在StringGrid1Click中写了这样的语句:
if (stringgrid1.Cells[stringgrid1.col,0]<>'BMMC') and (stringgrid1.Cells[stringgrid1.col,0]=dbedit1.datafield) then
begin
DBEdit1.Visible:=true;
DBComboBox1.Visible:=false;
end
else
begin
if (stringgrid1.Cells[stringgrid1.col,0]=DBComboBox1.DataField) then
begin
DBEdit1.Visible:=false;
DBComboBox1.Visible:=true;
//stringgrid1.Cells[stringgrid1.col,stringgrid1.row]:=DBComboBox1.text;
end;
end;
作完这些之后,控件可以画上,但是我每次点击一个单元格,显示的数据就很乱,总是显示最后一条信息,并且也不能修改,请各位高手给休整休整,谢谢
...全文
70 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fjy351 2001-11-28
  • 打赏
  • 举报
回复
这个问题这个难吗?竟然没有一个会的
fjy351 2001-11-28
  • 打赏
  • 举报
回复
这个问题,请大家帮忙啊
fjy351 2001-11-27
  • 打赏
  • 举报
回复
怎么没人回答呢?

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧