Lainkes 0 Posted March 16 Hello, I guess it's an easy solution, but how do I check if a record is selected in a DBGrid? If not selected, a button must be greyed out. If a record is selected, the button becomes active. Thanks Alain Share this post Link to post
Stano 143 Posted March 16 I kind of don't understand your problem. What are you actually pursuing? If you have only one record then the active buttons in the Navigator will be Insert/New, Edit and Delete. This is to say that you can't rely on the cursor buttons. It is better to work with the attached DataSet. Either it has an active/selected record or it doesn't. If you have something else in mind, then describe it more precisely. Share this post Link to post
Lainkes 0 Posted March 16 Hello, If a record (person) is selected in the DBGrid, there is a button that must be enabled.. The code behind the button links a new record to that perosn. So if no person is selected, the button must be disabled. Alain Share this post Link to post
Uwe Raabe 2057 Posted March 16 Perhaps I have a different concept of selected, but any non-empty dataset always has a current record, wich is where the indicator is when dgIndicator is part of the options. The field values from the dataset resemble this current record/row. In addition to this current row, a TDBGrid also has some SelectedRows represented by a TBookmarkList. So with 45 minutes ago, Lainkes said: If a record (person) is selected in the DBGrid do you mean the current row or the bookmark list? Share this post Link to post
Lainkes 0 Posted March 17 Quote any non-empty dataset always has a current record, Indeed. I did not notice that. Thanks for the tip. So I don't need to check. Share this post Link to post
Stano 143 Posted March 17 It seems to me that you are referring to the Master - detail link. That is handled differently. If it is something else so: the button bothers me a lot I would run the code every time I change a record but the code is time consuming... Which of these applies? Share this post Link to post
JohnLM 14 Posted March 17 @Lainkes - this is probably what you are after. Put the if/then code snippet (below) into the OnColEnter event of the DBGrid. And every time you enter that field that you set .FieldName='myfieldname' to, will highlight your button bold or non-bold. procedure TForm1.dbgrid1ColEnter(Sender: TObject); begin if db1.SelectedField.FieldName='myfieldname' then button1.Font.Style := [fsBold] else button1.Font.Style := []; end; Share this post Link to post