tags:

views:

397

answers:

4
+1  Q: 

TDBGrid onSelect

Hi,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

A: 

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.

Toby Allen
A: 

> 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)

A: 

You would need to check changes in the Selected property.

Osama ALASSIRY
+1  A: 

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;
JosephStyons