Как создать ComboBox внутри TStringGrid
interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids,stdctrls; type TBWControlStringGrid = class(TStringGrid) private fComboBox:TCombobox; Procedure WMCommand( var msg: TWMCommand ); message WM_COMMAND; procedure DblClick;override; procedure Click;override; procedure RelocateComboBox; procedure HideCombobox; protected procedure KeyPress(var Key: Char); override; public Constructor Create(AOWner:TComponent);override; Destructor Destroy;override; published end; procedure Register; implementation procedure Register; begin RegisterComponents('hEaDRoOm', [TBWControlStringGrid]); end; procedure TBWControlStringGrid.WMCommand(var msg: TWMCommand); begin If EditorMode and ( msg.Ctl = fComboBox.Handle ) Then inherited Else If msg.Ctl <> 0 Then msg.result := SendMessage( msg.ctl, CN_COMMAND, TMessage(msg).wparam, TMessage(msg).lparam ); end; procedure TBWControlStringGrid.KeyPress(var Key: Char); begin if Key=#13 then RelocateComboBox else HideCombobox; end; procedure TBWControlStringGrid.DblClick; begin inherited; RelocateComboBox; end; procedure TBWControlStringGrid.Click; begin inherited; HideCombobox; end; procedure TBWControlStringGrid.RelocateComboBox; begin fcombobox.boundsrect := CellRect( Selection.Left, Selection.Top); fcomboBox.Visible:=TRUE; fcombobox.setfocus; end; procedure TBWControlStringGrid.HideCombobox; begin fcomboBox.Visible:=false; end; Constructor TBWControlStringGrid.Create(AOWner:TComponent); begin inherited Create(Aowner); fComboBox:=TComboBox.Create(self); fComboBox.Parent:=self; fComboBox.Visible:=FALSE; Options:=Options-[goRangeSelect]; end; Destructor TBWControlStringGrid.Destroy; begin fComboBox.Destroy; inherited destroy; end; end.
Это конечно, только скелет...
Должен иметься механизм для получения/выбора текста из ComboBox в ячейку, а также для передачи содержания ячеек в ComboBox.
Комментарии