dbgrideh 如何内置编辑器ComboBox(100)

  • 主题发起人 主题发起人 guming1
  • 开始时间 开始时间
G

guming1

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,在dbgrideh的编辑框中内置ComboBox
 
加一临时字段~`再把字段设为combobox 不知道是你所要的~
 
不是很懂啊。。为什么要设置临时字段
 
procedure TForm_Edit_ZCB.dg_CBDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState);var tmpComboBox: TComboBox;//显示在DBGrid上的ComboBox ComboBoxName: string;//显示在DBGrid上的ComboBox名称 tmpField: TField;//关联的字段 FieldName: string; //字段名称 SQL: string; //关联的SQL GLComboBoxName: string; //字段关联的ComboBox名称begin inherited; if not FComboBoxStats then Exit; if (gdFocused in State) then begin tmpField:= Column.Field; if tmpField = nil then Exit; FieldName:= tmpField.FieldName; if p_Sys.p_FieldList[tmpField.Tag].Field3 = '' then Exit; DBGridCol:= TDrawGrid(dg_CB).col + 1; p_Sys.iOpen('select * from xt_table where tablebm = ''' + p_FormRecord.TableBM_CB + ''' and fieldname = ''' + FieldName + ''''); if dm.tmp_Data.RecordCount = 0 then Exit; ComboBoxName:= 'T_' + p_Sys.p_FieldList[tmpField.Tag].Field3 + '_C'; if Self.FindComponent(ComboBoxName) = nil then begin tmpComboBox:= TSSTComboBox.Create(Self); tmpComboBox.Name:= ComboBoxName; end else tmpComboBox:= TSSTComboBox(Self.FindComponent(ComboBoxName)); tmpComboBox.STag:= FieldName; tmpComboBox.Visible:= true; tmpComboBox.Parent:= Self; tmpComboBox.DCOMCon:= dm.DCOMCon; tmpComboBox.OnExit:= Self.ComboBoxOnExit; SQL:= dm.tmp_Data.FieldByName('glsql').AsString; if pos(':',SQL) > 0 then begin //'T_DWMC_SP1' ' T_DWMC_SP1' GLComboBoxName:= trim(copy(SQL,pos(':',SQL) + 1,100)); if Self.GetObjectText(GLComboBoxName) = '' then begin TSSTComboBox(Self.FindComponent(GLComboBoxName)).SetFocus; ShowMessage('请先输入关联数据'); Exit; end; SQL:= copy(SQL,1,pos(':',SQL) - 1) + Self.GetObjectText(GLComboBoxName); end; tmpComboBox.SQL:= SQL; tmpComboBox.QueryKey1:= dm.tmp_Data.FieldByName('jszd1').AsString; tmpComboBox.QueryKey2:= dm.tmp_Data.FieldByName('jszd2').AsString; tmpComboBox.FrameVisible:= true; tmpComboBox.Left := Rect.Left + dg_CB.Left; tmpComboBox.Top := Rect.Top + dg_CB.top; tmpComboBox.Width := Rect.Right - Rect.Left; tmpComboBox.Height := Rect.Bottom - Rect.Top; if p_CB.FieldByName(FieldName).AsString <> '' then tmpComboBox.BH:= p_CB.FieldByName(FieldName).AsString; //tmpComboBox.SetFocus; end;end;
 
设置dbgrideh.FieldColumn['FieldName'].PickList就能达到效果,内嵌combobox不是好的选择
 
后退
顶部