Daniel Grillo
Daniel Grillo

Reputation: 2418

hyperlink field in DBGRID

I'm doing a small internal software to search branch lines in my company. In addition to the branch lines I also put an e-mail field in the database as shown below:

enter image description here

My intention is to click on the registered e-mail and the software via the ShellExecute open a window to send the e-mail. I'm using the option dgRowSelect as TRUE and because of that the OnCellClick event does not correctly identify which cell was clicked.

In my searches have not found any way to do this. Then I thought of using a TLabel within the field. I can use the onclick event in the TLabel and also change the cursor icon.

If TLabel is a good solution, how can I add a TLabel in DBGrid?

Or what would be another good solution?

Upvotes: 1

Views: 2163

Answers (1)

user3421422
user3421422

Reputation: 51

I'm guessing that purpose of dgRowSelect=true is for highlighting whole selected row. TLabel is not the way I would go - I would set dgRowSelect=false and paint selected row in OnDrawColumnCell or create my own fixed dbgrid. There was a similar question: how can i colour whole row in DBGrid with rowselect turned off?

Anyway if you want to use dgRowSelect=true and get valid info about clicked cell, here it is:

type THackDBGrid=class(TDBGrid);


procedure TForm1.dbgrd1CellClick(Column: TColumn);
var p:TPoint;
    col:TGridCoord;
    i: Integer;
    grid:THackDBGrid;

begin
    p := Mouse.CursorPos;
    grid := THackDBGrid(Column.Grid);
    p := grid.ScreenToClient(p);
    col := grid.MouseCoord(p.X,p.Y);
    i := grid.RawToDataColumn(col.X);
    Label1.Caption := 'Column index: ' +  IntToStr(i);
end;

Upvotes: 1

Related Questions