在DBGrid的OnKeyDown事件中加入以下代码
var
Index: Integer;
begin
if DBGrid1.Columns[DBGrid1.SelectedIndex].PickList.Text<>'' then
begin
if (Key=VK_UP) or (Key=VK_DOWN) then
begin
DBGrid1.DataSource.DataSet.Edit;
Index:=DBGrid1.Columns[DBGrid1.SelectedIndex].PickList.IndexOf(DBGrid1.Columns[DBGrid1.SelectedIndex].Field.AsString);
if Index=-1 then
DBGrid1.Columns[DBGrid1.SelectedIndex].Field.AsString:=DBGrid1.Columns[DBGrid1.SelectedIndex].PickList.Strings[0]
else if Key=VK_UP then
begin
if Index=0 then
DBGrid1.Columns[DBGrid1.SelectedIndex].Field.AsString:=DBGrid1.Columns[DBGrid1.SelectedIndex].PickList.Strings[0]
else
DBGrid1.Columns[DBGrid1.SelectedIndex].Field.AsString:=DBGrid1.Columns[DBGrid1.SelectedIndex].PickList.Strings[Index-1]
end
else if Key=VK_DOWN then
if Index=DBGrid1.Columns[DBGrid1.SelectedIndex].PickList.Count-1 then
DBGrid1.Columns[DBGrid1.SelectedIndex].Field.AsString:=DBGrid1.Columns[DBGrid1.SelectedIndex].PickList.Strings[Index]
else
DBGrid1.Columns[DBGrid1.SelectedIndex].Field.AsString:=DBGrid1.Columns[DBGrid1.SelectedIndex].PickList.Strings[Index+1];
DBGrid1.DataSource.DataSet.Post;
Key:=0;
end;
end;
end;