lcl: enter in Edit state before item is changed in TDB*ListBox

git-svn-id: trunk@32503 -
This commit is contained in:
blikblum 2011-09-24 18:14:09 +00:00
parent 7c1c1c2e3e
commit 230dedbde2
4 changed files with 21 additions and 33 deletions

View File

@ -350,6 +350,7 @@ Type
procedure UpdateData(Sender: TObject); virtual; procedure UpdateData(Sender: TObject); virtual;
// we need to override the Items Write method for db aware. // we need to override the Items Write method for db aware.
procedure SetItems(Values : TStrings); override; procedure SetItems(Values : TStrings); override;
procedure WMLButtonDown(var Message: TLMLButtonDown); message LM_LBUTTONDOWN;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;

View File

@ -60,6 +60,12 @@ begin
DataChange(Self); DataChange(Self);
end; end;
procedure TCustomDBListBox.WMLButtonDown(var Message: TLMLButtonDown);
begin
FDataLink.Edit;
inherited;
end;
//we want to override the readonly state so we can //we want to override the readonly state so we can
//reflect the state of the Datalink/Field //reflect the state of the Datalink/Field
function TCustomDBListBox.GetReadOnly: Boolean; function TCustomDBListBox.GetReadOnly: Boolean;
@ -99,10 +105,17 @@ end;
procedure TCustomDBListBox.KeyDown(var Key: Word; Shift: TShiftState); procedure TCustomDBListBox.KeyDown(var Key: Word; Shift: TShiftState);
begin begin
inherited KeyDown(Key,Shift); inherited KeyDown(Key,Shift);
if Key=VK_ESCAPE then begin case Key of
//cancel out of editing by reset on esc VK_ESCAPE:
FDataLink.Reset; begin
Key := VK_UNKNOWN; //cancel out of editing by reset on esc
FDataLink.Reset;
Key := VK_UNKNOWN;
end;
VK_DOWN, VK_UP:
begin
FDataLink.Edit;
end;
end; end;
end; end;

View File

@ -39,20 +39,7 @@ end;
procedure TDBListBox.DoSelectionChange(User: Boolean); procedure TDBListBox.DoSelectionChange(User: Boolean);
begin begin
if User then if User then
begin FDataLink.Modified;
//make sure we are in modify mode if can edit
//so if a user changed the selection it can be
//updated, and if not cancel out ala ReadOnly
if FDataLink.Edit then
FDataLink.Modified
else
begin
// restore value
DataChange(Self);
//necessary to avoid double call of SelectionChange
Exit;
end;
end;
inherited DoSelectionChange(User); inherited DoSelectionChange(User);
end; end;

View File

@ -62,21 +62,8 @@ procedure TDBLookupListBox.DoSelectionChange(User: Boolean);
begin begin
if User then if User then
begin begin
//make sure we are in modify mode if can edit FDataLink.Modified;
//so if a user changed the selection it can be FDataLink.UpdateRecord;
//updated, and if not cancel out ala ReadOnly
if FDataLink.Edit then
begin
FDataLink.Modified;
FDataLink.UpdateRecord;
end
else
begin
// restore value
DataChange(Self);
//necessary to avoid double call of SelectionChange
Exit;
end;
end; end;
inherited DoSelectionChange(User); inherited DoSelectionChange(User);
end; end;