Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

DbGrid Columns (Mouse Button ?) EXPERT

TiefTief Member Posts: 179
[b][red]This message was edited by Tief at 2002-10-18 12:51:10[/red][/b][hr]
Hi,

I would like to know how to get the mouse button that was used to click on the OnTitleClick event. (TMouseButton) ?

OR

I would like to know what column is clicked on the OnMouseDown Event

Thanks

Tief


Comments

  • zibadianzibadian Member Posts: 6,349
    : [b][red]This message was edited by Tief at 2002-10-18 12:51:10[/red][/b][hr]
    : Hi,
    :
    : I would like to know how to get the mouse button that was used to click on the OnTitleClick event. (TMouseButton) ?
    :
    : OR
    :
    : I would like to know what column is clicked on the OnMouseDown Event
    :
    : Thanks
    :
    : Tief
    :
    :
    :
    According to the help files an OnTitleClick only occurs as response to a left-click. I haven't been able to find the screen position of the individual columns, but here is what I could come up with.
    Each Column has a width property, you could try to walk through the columns and calculate the Left and Right position of each column. Then you can determine in which column the X-parameter (OnMouseDown) is located.
  • TiefTief Member Posts: 179
    : : [b][red]This message was edited by Tief at 2002-10-18 12:51:10[/red][/b][hr]
    : : Hi,
    : :
    : : I would like to know how to get the mouse button that was used to click on the OnTitleClick event. (TMouseButton) ?
    : :
    : : OR
    : :
    : : I would like to know what column is clicked on the OnMouseDown Event
    : :
    : : Thanks
    : :
    : : Tief

    : :
    : :
    : :
    : According to the help files an OnTitleClick only occurs as response to a left-click. I haven't been able to find the screen position of the individual columns, but here is what I could come up with.
    : Each Column has a width property, you could try to walk through the columns and calculate the Left and Right position of each column. Then you can determine in which column the X-parameter (OnMouseDown) is located.
    :

    That's a brilliant idea !! Thanks, I will try it.

    Tief

  • TiefTief Member Posts: 179
    : : : [b][red]This message was edited by Tief at 2002-10-18 12:51:10[/red][/b][hr]
    : : : Hi,
    : : :
    : : : I would like to know how to get the mouse button that was used to click on the OnTitleClick event. (TMouseButton) ?
    : : :
    : : : OR
    : : :
    : : : I would like to know what column is clicked on the OnMouseDown Event
    : : :
    : : : Thanks
    : : :
    : : : Tief
    :
    : : :
    : : :
    : : :
    : : According to the help files an OnTitleClick only occurs as response to a left-click. I haven't been able to find the screen position of the individual columns, but here is what I could come up with.
    : : Each Column has a width property, you could try to walk through the columns and calculate the Left and Right position of each column. Then you can determine in which column the X-parameter (OnMouseDown) is located.
    : :
    :
    : That's a brilliant idea !! Thanks, I will try it.
    :
    : Tief
    :
    :

    This thing work perfectly ! Thanks ! Here's the code.

    PS: For the people of this forum. When You actually find the answer to your problem. Please Reply to your own message with the answer or code. This enables other people to read your question and answer. It really help.

    //**********************************************************************
    // (PRIVATE) GET COLUMN CLICK
    function TFrmFile.GetColumnClick( const X : Integer) : TColumn;
    var
    I : Integer;
    Left : Integer;
    begin
    Left := 0;

    For I := 0 to Self.DBGrid.Columns.Count - 1 do
    begin
    if (X >= Left) and (X <= Left + Self.DBGrid.Columns.Items [I].Width) then
    begin
    Result := Self.DBGrid.Columns.Items[I];
    exit;
    end
    else
    Left := Left + Self.DBGrid.Columns.Items[I].Width;
    end;

    Result := nil;
    end;

  • Jerry@WGJerry@WG Member Posts: 17
    : : [b][red]This message was edited by Tief at 2002-10-18 12:51:10[/red][/b][hr]
    : : Hi,
    : :
    : : I would like to know how to get the mouse button that was used to click on the OnTitleClick event. (TMouseButton) ?
    : :
    : : OR
    : :
    : : I would like to know what column is clicked on the OnMouseDown Event
    : :
    : : Thanks
    : :
    : : Tief
    : :
    : :
    : :
    : According to the help files an OnTitleClick only occurs as response to a left-click. I haven't been able to find the screen position of the individual columns, but here is what I could come up with.
    : Each Column has a width property, you could try to walk through the columns and calculate the Left and Right position of each column. Then you can determine in which column the X-parameter (OnMouseDown) is located.
    :

    You could do that, or you could use the MouseCoord method of the DBGrid to find the row and column where the mouse was at when it was clicked.

  • TiefTief Member Posts: 179
    [b][red]This message was edited by Tief at 2002-10-23 8:12:54[/red][/b][hr]
    [b][red]This message was edited by Tief at 2002-10-23 8:11:58[/red][/b][hr]
    : : : [b][red]This message was edited by Tief at 2002-10-18 12:51:10[/red][/b][hr]
    : : : Hi,
    : : :
    : : : I would like to know how to get the mouse button that was used to click on the OnTitleClick event. (TMouseButton) ?
    : : :
    : : : OR
    : : :
    : : : I would like to know what column is clicked on the OnMouseDown Event
    : : :
    : : : Thanks
    : : :
    : : : Tief
    : : :
    : : :
    : : :
    : : According to the help files an OnTitleClick only occurs as response to a left-click. I haven't been able to find the screen position of the individual columns, but here is what I could come up with.
    : : Each Column has a width property, you could try to walk through the columns and calculate the Left and Right position of each column. Then you can determine in which column the X-parameter (OnMouseDown) is located.
    : :
    :
    : You could do that, or you could use the MouseCoord method of the DBGrid to find the row and column where the mouse was at when it was clicked.
    :
    :

    Hi It's me again, The solution I posted above does work, but has bugs in it. Do not use the code.

    Here's the best way to solve this problem.

    Open the DbGrid.pas in the BolandDelhpi6SourceVcl folder.

    In CustomDbGrid class.

    Add in the Private section ( CustomDBGrid )
    ...
    FColumnClicked : TColumn;
    ...
    and Add in the Public section ( CustomDBGrid )
    ...
    property ColumnClicked : TColumn read FColumnClicked write FColumnClicked;
    ...

    Now in the MouseDown ( CustomDBGrid ) procedure Add this code;
    ...
    procedure TCustomDBGrid.MouseDown(Button: TMouseButton; Shift: TShiftState;
    X, Y: Integer);
    var
    Cell: TGridCoord;
    OldCol,OldRow: Integer;
    MasterCol: TColumn;
    begin

    //****************** ADDED CODE ******************

    Cell := MouseCoord(X,Y);

    if (Cell.X >= FIndicatorOffset) and (Cell.Y >= 0) then
    begin
    if Cell.Y < FTitleOffset then
    Self.FColumnClicked := Columns[RawToDataColumn(Cell.X)]
    else
    Self.FColumnClicked := Columns[SelectedIndex];
    end;

    //****************** END OF ADDED CODE ******************

    if not AcquireFocus then Exit;
    if (ssDouble in Shift) and (Button = mbLeft) then
    begin
    DblClick;
    Exit;
    end;
    ...

    Finally Add in the Published section (DBGrid) this line
    ...
    property ColumnClicked;
    ...

    Now Each time you click a column in a dbgrid. The Property ColumnClicked will help you get the column that was click. This can be useful on the OnMouseDown Event.

    Have Fun

    Tief




  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    _ ( http://forcoder.org ) free ebooks and video tutorials about / Perl, Go, Assembly, Java, Python, PHP, Visual Basic .NET, C#, C, Delphi, MATLAB, PL/SQL, Scratch, JavaScript, Swift, C++, Objective-C, Ruby, R, Visual Basic Logo, Ada, COBOL, Scheme, Julia, Rust, ML, Lisp, Dart, SAS, Apex, Lua, Kotlin, ABAP, F#, Transact-SQL, Hack, LabVIEW, Clojure, Fortran, Erlang, Awk, VBScript, Prolog, Crystal, FoxPro, Alice, Scala, D, Bash / ___

Sign In or Register to comment.