yippee
yippee

Reputation:

TDBGrid onSelect

I would like to customize TDBGrid:

1) add onSelect/onUnselect events - e.g. good for show count of selected items.

2) remove select item on left mouse click. I have inherited TDBGrid and rewritten MouseDown, but then it is not possible to move or resize columns :(

So, how to do it?

D2009

Upvotes: 1

Views: 1426

Answers (4)

JosephStyons
JosephStyons

Reputation: 58795

This gets the job done for me:

implementation

{$R *.dfm}

type
  THackDBGrid = class(TDBGrid);
//for info on why we must do this, see:
//http://delphi.about.com/od/oopindelphi/l/aa082603a.htm

var
  LastValidRow: integer;

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
  //assign this to the TDBGrid.DataSource.DataSet.OnDataChange Event
  if 0 <> HiWord(GetKeyState(VK_LBUTTON)) then begin
    THackDBGrid(DBGrid1).Row := LastValidRow;
  end
  else begin
    LastValidRow := THackDBGrid(DBGrid1).Row;
    inherited;
  end;
end;

Upvotes: 1

Osama Al-Maadeed
Osama Al-Maadeed

Reputation: 5695

You would need to check changes in the Selected property.

Upvotes: 1

yippee
yippee

Reputation:

> I think you probably need to make sure you allow the inherited Mousedown to run so that the standard move and resize behaviour will execute.

But inherited MouseDOwn make select on left mouse button and I want only select/unselect on right mouse button (such as select/unselect in TotalComander)

Upvotes: 0

Toby Allen
Toby Allen

Reputation: 11221

I think you probably need to make sure you allow the inherited Mousedown to run so that the standard move and resize behaviour will execute.

Upvotes: 0

Related Questions