Avatar of Norm-al
Flag 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.
Microsoft SQL Server 2005Delphi

Avatar of undefined
Last Comment
Ephraim Wangoya

8/22/2022 - Mon

Try something like this...


Open in new window


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?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.

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

CodeGear Delphi 2007, version 11.0.2902.10471
Ephraim Wangoya

What grid component are you using?

A devExpress tcxGrid.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Ephraim Wangoya


How About this?


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

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? :(
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

Glad it helped.
Ephraim Wangoya

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;