CodedK
asked on
DBGrid and mouse.
I'd like the following to happen with a dbgrid:
When the mouse pointer is over a particular column then ...
take the number that lies under the mouse pointer in the current cell and store it in a string !.
Then take the number of the next column in the same line...and store it in a string
Thanks in advance. :)
When the mouse pointer is over a particular column then ...
take the number that lies under the mouse pointer in the current cell and store it in a string !.
Then take the number of the next column in the same line...and store it in a string
Thanks in advance. :)
Sorry I take that back I will continue to look at it
Make your own vcl derived from DBGrid.
OnMouseMove:
...
var f : TField;
LogCol,
LogRow : Longint;
OldActive : integer;
text: string;
Cell:TGridCoord;
begin
Cell:=MouseCoord(X,Y);
LogCol:= Cell.X;
LogRow:= Cell.Y;
if dgTitles in Options then
Dec(LogRow);
if dgIndicator in Options then
Dec(LogCol);
if (DataLink.Active) and (LogCol >= 0) and (LogRow >= 0) then
begin
OldActive:= DataLink.ActiveRecord;
try
DataLink.ActiveRecord:= LogRow;
f:=Columns[LogCol].field;
try
Text:= Columns[LogCol].Field.AsSt ring
except
Text:= Columns[LogCol].Field.Disp layText;
end;
finally
DataLink.ActiveRecord:= OldActive ;
end;
end;
end;
For next colum text use:
Text:= Columns[LogCol+1].Field.As String
OnMouseMove:
...
var f : TField;
LogCol,
LogRow : Longint;
OldActive : integer;
text: string;
Cell:TGridCoord;
begin
Cell:=MouseCoord(X,Y);
LogCol:= Cell.X;
LogRow:= Cell.Y;
if dgTitles in Options then
Dec(LogRow);
if dgIndicator in Options then
Dec(LogCol);
if (DataLink.Active) and (LogCol >= 0) and (LogRow >= 0) then
begin
OldActive:= DataLink.ActiveRecord;
try
DataLink.ActiveRecord:= LogRow;
f:=Columns[LogCol].field;
try
Text:= Columns[LogCol].Field.AsSt
except
Text:= Columns[LogCol].Field.Disp
end;
finally
DataLink.ActiveRecord:= OldActive ;
end;
end;
end;
For next colum text use:
Text:= Columns[LogCol+1].Field.As
ASKER
Hi.
Ginsonic there is a problem with DataLink
(Undeclared udentifier)
Tried Dbgrid1.Data... but no luck.. how should i write that ?
Thanks :)
Ginsonic there is a problem with DataLink
(Undeclared udentifier)
Tried Dbgrid1.Data... but no luck.. how should i write that ?
Thanks :)
You must create your own DBGrid to say MyDBGrid: TDBGrid;
And then use MyDBGrid instead of DBGrid1 in you project.
type
TMyDBGrid = class(TDBGrid)
protected
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
end;
...
procedure TMyDBGrid.MouseMove(Shift: TShiftState; X, Y: Integer);
And then use MyDBGrid instead of DBGrid1 in you project.
type
TMyDBGrid = class(TDBGrid)
protected
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
end;
...
procedure TMyDBGrid.MouseMove(Shift:
ASKER
Ok i'll check it. :)
But will this do the job for the existing dbgrid ?
By the way have you checked the "Screen Cam Component" ?
Thanks :)
But will this do the job for the existing dbgrid ?
By the way have you checked the "Screen Cam Component" ?
Thanks :)
ASKER
Ok i created MyDbgrid.
the code is this..
procedure TMyDBGrid.MouseMove(Shift: TShiftState; X, Y: Integer);
var f : TField;
LogCol,LogRow: Longint;
OldActive : integer;
text: String;
Cell:TGridCoord;
begin
Cell:=MouseCoord(X,Y);
LogCol:= Cell.X;
LogRow:= Cell.Y;
if dgTitles in Options then
Dec(LogRow);
if dgIndicator in Options then
Dec(LogCol);
if (DataLink.Active) and (LogCol >= 0) and (LogRow >= 0) then
begin
OldActive:= DataLink.ActiveRecord;
try
DataLink.ActiveRecord:= LogRow;
f:=Columns[LogCol].field;
try
Text:= Columns[LogCol].Field.AsSt ring
except
Text:= Columns[LogCol].Field.Disp layText;
end;
finally
DataLink.ActiveRecord:= OldActive ;
end;
end;
end
the code is this..
procedure TMyDBGrid.MouseMove(Shift:
var f : TField;
LogCol,LogRow: Longint;
OldActive : integer;
text: String;
Cell:TGridCoord;
begin
Cell:=MouseCoord(X,Y);
LogCol:= Cell.X;
LogRow:= Cell.Y;
if dgTitles in Options then
Dec(LogRow);
if dgIndicator in Options then
Dec(LogCol);
if (DataLink.Active) and (LogCol >= 0) and (LogRow >= 0) then
begin
OldActive:= DataLink.ActiveRecord;
try
DataLink.ActiveRecord:= LogRow;
f:=Columns[LogCol].field;
try
Text:= Columns[LogCol].Field.AsSt
except
Text:= Columns[LogCol].Field.Disp
end;
finally
DataLink.ActiveRecord:= OldActive ;
end;
end;
end
ASKER
How to invoke the text to appear?
you can add a property into public declaration. Or a function.
......
private
Text: string;
public
function GetText: string;
.....
function TMyDBGrid: string;
begin
Result:=Text;
end;
Don't forget to remove Text: string from OnMouse procedure ( don't declare twice ).
About Scam I don't think that willhelp me. I need something regarding overlaying.
Nick
......
private
Text: string;
public
function GetText: string;
.....
function TMyDBGrid: string;
begin
Result:=Text;
end;
Don't forget to remove Text: string from OnMouse procedure ( don't declare twice ).
About Scam I don't think that willhelp me. I need something regarding overlaying.
Nick
And to read use in form:
Label1.Caption:=MyDBGrid1. GetText;
Label1.Caption:=MyDBGrid1.
ASKER
Ginsonic.. Sorry for not understanding :))
but this is what i use :
TForm1.DBGrid1MouseMove //Dbgrid1 the old dbgrid
Begin
Form1.Caption:=Text1
End;
I've declared text1 as string at general variables..
But i get nothing when the mouse move on dbgrid1...
???Is it necessary to create a function ?
Thanks for ur time :)
but this is what i use :
TForm1.DBGrid1MouseMove //Dbgrid1 the old dbgrid
Begin
Form1.Caption:=Text1
End;
I've declared text1 as string at general variables..
But i get nothing when the mouse move on dbgrid1...
???Is it necessary to create a function ?
Thanks for ur time :)
ASKER
And ofcourse text1 is the string name i use in the code u gave me .
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Problems ?
ASKER
No :)
No problems ginsonic ... Sorry for the delay and thank you for your help :)))
I'll just need one more day to check the codes ... i'm away :/
Thank you :)
No problems ginsonic ... Sorry for the delay and thank you for your help :)))
I'll just need one more day to check the codes ... i'm away :/
Thank you :)
ASKER
Ok ...
I checked it.
The code produce no errors.
But when i put the 'GetText' on the 'DBGrid1MouseMove' event :
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
procedure TForm2.DBGrid1MouseMove(Se nder: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Label1.Caption:=DBGrid1.Ge tText;
end;
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
I get undeclared identifier for GetText !
I also tried:
Label1.Caption:=MyDBGrid.G etText;
Did u check it?
Please help coz i cant make it work ...
:)
I checked it.
The code produce no errors.
But when i put the 'GetText' on the 'DBGrid1MouseMove' event :
--------------------------
procedure TForm2.DBGrid1MouseMove(Se
Y: Integer);
begin
Label1.Caption:=DBGrid1.Ge
end;
--------------------------
I get undeclared identifier for GetText !
I also tried:
Label1.Caption:=MyDBGrid.G
Did u check it?
Please help coz i cant make it work ...
:)
Don't use DBGrid. Use our new class MyDBGrid.
Take the component code and save it into a unit named myDBGrid. Install the component. Open the Form1 and replace the standard DBGrid with MyDBGrid. Can find it in Nick's category on vcl pallete.
Take the component code and save it into a unit named myDBGrid. Install the component. Open the Form1 and replace the standard DBGrid with MyDBGrid. Can find it in Nick's category on vcl pallete.
Here work perfect.
ASKER
Ok.
Increased points to 500...
Please help coz its the first time i do this :)
I saved it with the name 'MyDBGrid'.
I installed it as a component - 'Into Existing Package'.
I closed everything and went back to my Project.
Now ... this is a huge project (for me it is) and i can do it from the beggining again. :/
So... OnMouse event on DBGrid1, i tried to write 'MyDBGrid. Something' but errors occured... ofcourse...
So there is a' Nicks' tab, with a DBGrid that i can drop in my form... :/ :/ But then i should right all the code from the start... :(
(2352 lines) ...
Is there any other way ?
I m trying to capture the string from the cell to invoke a hint (or a form)
to come up everytime the mouse is over a particular cell...
I searched EE and found some codes:
This one points to a 3rd party software
https://www.experts-exchange.com/questions/20636690/Hints-in-dbGrid.html?query=hint+dbgrid&clearTAFilter=true
This one is small and very promissing ... but cant make it work.
It didnt worked for the asker either.. I guess.
https://www.experts-exchange.com/questions/21048106/Hint-on-a-cell-in-a-DBGrid.html?query=hint+dbgrid&clearTAFilter=true
This one refers to a sample that was never there !
https://www.experts-exchange.com/questions/21040980/When-I-click-a-memo-in-a-Dbgrid-Can-I-dispaly-a-small-box-that-shows-the-detail-of-the-memo.html?query=hint+dbgrid&clearTAFilter=true
Anyway .. I appreciate your time.
Plz tell if there is an other way.. or even a more simple solution (than replacing .. rewriting the whole project)
Thank u very much !
Increased points to 500...
Please help coz its the first time i do this :)
I saved it with the name 'MyDBGrid'.
I installed it as a component - 'Into Existing Package'.
I closed everything and went back to my Project.
Now ... this is a huge project (for me it is) and i can do it from the beggining again. :/
So... OnMouse event on DBGrid1, i tried to write 'MyDBGrid. Something' but errors occured... ofcourse...
So there is a' Nicks' tab, with a DBGrid that i can drop in my form... :/ :/ But then i should right all the code from the start... :(
(2352 lines) ...
Is there any other way ?
I m trying to capture the string from the cell to invoke a hint (or a form)
to come up everytime the mouse is over a particular cell...
I searched EE and found some codes:
This one points to a 3rd party software
https://www.experts-exchange.com/questions/20636690/Hints-in-dbGrid.html?query=hint+dbgrid&clearTAFilter=true
This one is small and very promissing ... but cant make it work.
It didnt worked for the asker either.. I guess.
https://www.experts-exchange.com/questions/21048106/Hint-on-a-cell-in-a-DBGrid.html?query=hint+dbgrid&clearTAFilter=true
This one refers to a sample that was never there !
https://www.experts-exchange.com/questions/21040980/When-I-click-a-memo-in-a-Dbgrid-Can-I-dispaly-a-small-box-that-shows-the-detail-of-the-memo.html?query=hint+dbgrid&clearTAFilter=true
Anyway .. I appreciate your time.
Plz tell if there is an other way.. or even a more simple solution (than replacing .. rewriting the whole project)
Thank u very much !
You don't need rewrite the all application. Just drop the new VCL. Delete the old DBGrid. Rename MyDBGrid1 with DBGrid1. Assign all events of the old grid to the new. Is a DBGrid but with a new property. I think that you can replaced in max. 10 minutes.
I will thinking to a directly way but is a problem that if isn't inside a vcl unit DataLink can't be accessed. Don't understand way. Still digging.
ASKER
@I think that you can replaced in max. 10 minutes.
:)
I know... Allready did that.
But there is a problem with the language i use in the first DBGrid.
It keeps showing '@$##%#'...
I dropped our dbgrid and by pressing Shift i gave to 'MyDBGrid' all the things DBGrid1 has.. Fonts,Size,Data and all the other stuff...
Anyway :)
I'll find out whats wrong and replace anything with 'Mydbgrid' ...
I'll keep this question open, for a while, if u find anything about Hinds&Dbgrid ...
Thank u very much :)
:)
I know... Allready did that.
But there is a problem with the language i use in the first DBGrid.
It keeps showing '@$##%#'...
I dropped our dbgrid and by pressing Shift i gave to 'MyDBGrid' all the things DBGrid1 has.. Fonts,Size,Data and all the other stuff...
Anyway :)
I'll find out whats wrong and replace anything with 'Mydbgrid' ...
I'll keep this question open, for a while, if u find anything about Hinds&Dbgrid ...
Thank u very much :)
Take a look at http://www.torry.net/quicksearchd.php?SID=b5f74814bda808b8c35b4bb803ce5fec&String=bkgdbg&Title=Yes and see ve. 3.5 for BkgDBGrid. Something like this ?
>I dropped our dbgrid and by pressing Shift i gave to 'MyDBGrid' all the things DBGrid1 has.. Fonts,Size,Data and all the other stuff...
Can you tell me more ? Idon't know this way to replace. Sound great.
>But there is a problem with the language i use in the first DBGrid.
Don't understand the problem. Can you give me more details
Can you tell me more ? Idon't know this way to replace. Sound great.
>But there is a problem with the language i use in the first DBGrid.
Don't understand the problem. Can you give me more details
ASKER
:P
Glad to help :)
Well with shift you can select 2-3 or more objects and see their common attributes.
In the case of the 2 dbgrids all the attributes are the same.
By selecting for example on textbox and one label you have many common attributes..
Lets say Fonts.
The first object you'll select by pressing shift is the one that gives the attributes to the others..
(Hold Shift) click on a button then on a form... Then go to the 'Fonts' it shows the font of the button by pressing enter the form
borrows the button font attribute..
Thats what i did with 2 dbgrids, one by one i pressed enter etc...
:)
The link from Torry has a new dbgrid :/, i prefer to use 'MyDBGrid'.. If the case is to replace the 1st dbgrid...
I will leave this 1-2 days open ... Thanks :)
Glad to help :)
Well with shift you can select 2-3 or more objects and see their common attributes.
In the case of the 2 dbgrids all the attributes are the same.
By selecting for example on textbox and one label you have many common attributes..
Lets say Fonts.
The first object you'll select by pressing shift is the one that gives the attributes to the others..
(Hold Shift) click on a button then on a form... Then go to the 'Fonts' it shows the font of the button by pressing enter the form
borrows the button font attribute..
Thats what i did with 2 dbgrids, one by one i pressed enter etc...
:)
The link from Torry has a new dbgrid :/, i prefer to use 'MyDBGrid'.. If the case is to replace the 1st dbgrid...
I will leave this 1-2 days open ... Thanks :)
BkgDBGrid is my vcl. The solution proposed by me is part of this vcl.
I ask you to know if you need to show the text inside a hint or into label for example.
I ask you to know if you need to show the text inside a hint or into label for example.
ASKER
Inside a form like a hint... so i can configure it ... more...
or a hint... The thing is just to capture the string from the cell in dbgrid then i can do it what ever i want... :)
I'll give you the points now since no function ... or something like that is possible...
Thanks very much for your help ...
P.s if you find something else beside other vcl's please post ...
:)
or a hint... The thing is just to capture the string from the cell in dbgrid then i can do it what ever i want... :)
I'll give you the points now since no function ... or something like that is possible...
Thanks very much for your help ...
P.s if you find something else beside other vcl's please post ...
:)
Glad to can help you. Keep in touch!
TCGrid = class(TCustomDBGrid);
then use this in the mousemove of the grid
procedure TfrmMain.dbgDataMouseMove(
Y: Integer);
var
lCoord: tGridCoord;
ls: string;
begin
lCoord:=TCGrid(dbgData).Mo
if (lCoord.x>0) and (lCoord.y>0 )then
begin
ls:=ls+TCGrid(dbgData).Get
Caption:=ls;
end;
end;
regards