我在一个模式窗口中,有一个DBGridEh名为dbg, DataSet为代码中动态Active的,并在代码中动态将各列属性指定. 其中第3列(商品ID字段)要设置成可点击按钮后新开窗口选择的功能(选择后将所选ID赋给本字段),因为提供选择的数据很多,使用下拉列表的话不太好找到需要选择的内容.
现在用户提出要求需要可以直接输入并在保存时将输入的内容一并存盘. 但我现在发现设置按钮后,该列已经无法输入,不知道怎么让它在保留按钮功能的同时又可以输入?相关代码为: dbg.Columns[3].Title.Caption := '品 名';
dbg.Columns[3].Width := 200;
dbg.Columns[3].Alignment := taLeftJustify; //数据库中该字段为商品ID号, 默认情况下数字会右对齐显示
btn := dbg.Columns[3].EditButtons.Add;
btn.Style := ebsEllipsisEh;
btn.OnClick := WareEditButtonClick; //打开一个模式窗口让用户选择, 选择后会自动为相应列赋值
现在用户提出要求需要可以直接输入并在保存时将输入的内容一并存盘. 但我现在发现设置按钮后,该列已经无法输入,不知道怎么让它在保留按钮功能的同时又可以输入?相关代码为: dbg.Columns[3].Title.Caption := '品 名';
dbg.Columns[3].Width := 200;
dbg.Columns[3].Alignment := taLeftJustify; //数据库中该字段为商品ID号, 默认情况下数字会右对齐显示
btn := dbg.Columns[3].EditButtons.Add;
btn.Style := ebsEllipsisEh;
btn.OnClick := WareEditButtonClick; //打开一个模式窗口让用户选择, 选择后会自动为相应列赋值
加句就好了
var
qu: TADOQuery;
s: string;
begin
s := 'Select * from Ware where ID = ' + IntToStr(id);
qu := TADOQuery.Create(Self);
qu.Connection := DM.conn;
qu.SQL.Text := s;
qu.Active := True;
qu.First;
if not qu.Eof then
begin
s := qu.FieldByName('WareName').AsString;
if dbg.Columns[3].PickList.IndexOf(s) < 0 then // -1
begin //判断的目的是为了在DBGridEh第二行选择同样商品时不重复加入PickList中
dbg.Columns[3].PickList.Add(s);
dbg.Columns[3].KeyList.Add(IntToStr(id));
end;
//赋值后必须跳转焦点,否则不生效,造成只计算一行的金额
dbg.SelectedIndex := dbg.SelectedIndex + 2; //跳过两列
if bLoad then
begin
ds_invd.Edit;
ds_invd.FieldByName('Unit').AsString := qu.FieldByName('Unit').AsString;
ds_invd.FieldByName('Price').AsCurrency := qu.FieldByName('Price').AsCurrency;
end;
end; qu.Close;
qu.Free;
end;
dbg.Columns[3].Width := 200;
dbg.Columns[3].Alignment := taLeftJustify; //数据库中该字段为商品ID号, 默认情况下数字会右对齐显示
btn := dbg.Columns[3].EditButtons.Add;
btn.Style := ebsEllipsisEh;
btn.OnClick := WareEditButtonClick;
dbg.Columns[3].ReadOnly:=False;//加在这,应该有效果的
//主键列默认是不可修改的
当然如果我不加EditButton的话,就是可以修改的。但一旦使用了EditButton后就不能直接输入了,必须用按钮选择。
只是我现在想两种方式都能使用:按钮选择和直接输入。应该怎么办?
加了按钮是可以修改的