如果是静态添加:在第一列的PickList属性编辑框String List Editor中输入“男“,"女"。
如果是静态添加:在第一列的PickList属性编辑框String List Editor中输入“男“,"女"。但是动态的话 你要根据你的字段进行判断 然后在ONGETTEXT ONSETTEXT 事件中自己写了
我这有一个dbgrid的,自己参照着做吧。 procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState); begin if (gdFocused in State) then begin if (Field.FieldName = DBComboBox1.DataField ) then begin DBComboBox1.Left := Rect.Left + DBGrid1.Left; DBComboBox1.Top := Rect.Top + DBGrid1.top; DBComboBox1.Width := Rect.Right - Rect.Left; DBComboBox1.Height := Rect.Bottom - Rect.Top; DBComboBox1.Visible := True; end; end; end;procedure TForm1.DBGrid1ColExit(Sender: TObject); begin If DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then begin DBComboBox1.Visible := false; end; end;procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char); begin if (key <> chr(9)) then begin if (DBGrid1.SelectedField.FieldName =DBComboBox1.DataField) then begin DBComboBox1.SetFocus; SendMessage(DBComboBox1.Handle,WM_Char,word(Key),0); end; end; end;
可以动态调用PickList->LoadFromFile方法,把列表内容保存在文本文件里面。
Ivin(hx) 的方法还是不错的。我也学习ing.
有没有搞错??wwDBGrid中没有PickList的???
添加一个wwDBCombobox 设置好Datasoure和DataFiel后 双击WwDBGrid,弹出的窗体中添加Fields 再在对应的Field中设置EditControl页中的Control Type为CustomEidt Control Name为wwDBCombobox就行啦
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
if (gdFocused in State) then
begin
if (Field.FieldName = DBComboBox1.DataField ) then
begin
DBComboBox1.Left := Rect.Left + DBGrid1.Left;
DBComboBox1.Top := Rect.Top + DBGrid1.top;
DBComboBox1.Width := Rect.Right - Rect.Left;
DBComboBox1.Height := Rect.Bottom - Rect.Top;
DBComboBox1.Visible := True;
end;
end;
end;procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
If DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then
begin
DBComboBox1.Visible := false;
end;
end;procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if (key <> chr(9)) then
begin
if (DBGrid1.SelectedField.FieldName =DBComboBox1.DataField) then
begin
DBComboBox1.SetFocus;
SendMessage(DBComboBox1.Handle,WM_Char,word(Key),0);
end;
end;
end;
设置好Datasoure和DataFiel后
双击WwDBGrid,弹出的窗体中添加Fields
再在对应的Field中设置EditControl页中的Control Type为CustomEidt
Control Name为wwDBCombobox就行啦