يك راه ساده براي اينكار وجود داره.
شما كافيه بر روي رويداد مربوط به SelectCellدر dbgride برنامه ای بنویسید که اطلاعات مربوط را در یک کامبو باکس نشون بده. البته قبلش باید یک کامبو داشته باشید که دیده نشه. فقط هر بار که یک سلول در dbgride انتهاب میشه باید طول و عرض و همچنین جای combobox را طوری تنظیم کنید که کاربر تصور بکنه این کمبو مربوط به همون سلول هست.
procedure TFrmTKConsolidate.SGdDataSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); var R : TRect; S : String; I : Integer; CBx: TComboBox; TS : TStringList; begin IF NOT (ACol IN [1,2,4]) THEN Exit; { Size and position the combo box to fit the cell: } R := SGdData.CellRect(ACol, ARow); R.Left := R.Left + SGdData.Left; R.Right := R.Right + SGdData.Left; R.Top := R.Top + SGdData.Top; R.Bottom := R.Bottom + SGdData.Top; CBx := NIL; { Silence the compiler } CASE ACol OF 1: CBx := CBxProjects; 2: BEGIN CBx := CBxTasks; { Even vullen met de relevante taken } { 1. Projectnaam ophalen: } S := SGdData.Cells[1,ARow]; { 2. Omzetten naar projectID: } I := dmTK.GetProjID(S); { 3. Taken bij project ophalen: } TS := TStringList.Create; dmTk.UpdateTaskList(I,TS); { 4. In de combobox proppen: } CBx.Clear; CBx.Items.AddStrings(TS); { 5. Rommel opruimen } TS.Free; END; 4: CBx := CBxLocations; END; CBx.Left := R.Left + 1; CBx.Top := R.Top + 1; CBx.Width := (R.Right + 1) - R.Left; CBx.Height := (R.Bottom + 1) - R.Top; { Laat de itemindex van de combobox } { corresponderen met de celinhoud: } S := SGdData.Cells[ACol,ARow]; I := CBx.Items.IndexOf(S); CBx.ItemIndex := I; CBx.Visible := True; CBx.SetFocus; CanSelect := True; end; { SGdDataSelectCell } -3- Write OnExit handlers for the comboboxes: procedure TFrmTKConsolidate.CBxExit(Sender: TObject); VAR TCX: TComboBox; begin TCX := Sender as TComboBox; SGdData.Cells[SGdData.Col,SGdData.Row] := TCx.Items[TCx.ItemIndex]; TCx.Visible := False; SGdData.SetFocus; end; { CBxExit }