Link to home
Start Free TrialLog in
Avatar of Norm-al
Norm-alFlag for United States of America

asked on

Finding column selected in Delphi grid

Hi experts,

I have a double-click event in a Delphi grid which is opening a data entry form, but I need a way of determining which column the cell that was clicked resides in so that variable can be passed to the DEF.

I'm assuming this can be done fairly easily and probably in a few different ways; if possible, I would greatly appreciate being able to see a few different examples.
Avatar of edlunad
edlunad
Flag of United States of America image

Try something like this...

YourVar:=DBGrid1.SelectedField.FieldName;

Open in new window

Avatar of Norm-al

ASKER

I've been looking for an option like that but can't seem to find any sort of 'SelectedField' property under the grid...

The closest I've found is DBGrid1.Columns.FocusedCellViewInfo... but I'm not sure if I'm headed down the right path here.
What's your Delphi version?
Avatar of Norm-al

ASKER

Ah sorry, probably should have posted that to begin with:

CodeGear Delphi 2007, version 11.0.2902.10471
Avatar of Ephraim Wangoya

What grid component are you using?
Avatar of Norm-al

ASKER

A devExpress tcxGrid.

 TcxGridDBColumn(ACellViewInfo.Item).DataBinding.FieldName
How About this?

cxGrid1.Controller.FocusedColumn
ASKER CERTIFIED SOLUTION
Avatar of edlunad
edlunad
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Norm-al

ASKER

Ah, perfect!

cxGrid1.Controller.FocusedColumn.Name was exactly what I was looking for. I'm not sure why I didn't think to look under the .Controller property.

Going by the column index would also have worked, however the way that I am using referencing the variable from the DEF would mean that if the column were moved prior to it opening the index would be wrong.


ewangoya, your method of referencing the field name would also work just as well, but I can't seem to get it to work--it hits that line and errors out. What sort of simpleness am I screwing up? :(
Glad it helped.

I'm not sure why you could not get it to work, the item proprty references the column on the grid and you can typecast it to a DB Column

MyField := TcxGridDBColumn(ACellViewInfo.Item).DataBinding.FieldName;