Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6753319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:08:50+00:00 2026-05-26T13:08:50+00:00

I want to activate a cell in a TDBGrid by code. By activate I

  • 0

I want to activate a cell in a TDBGrid by code. By “activate” I mean like the user clicked inside the cell, ready to edit the cell content. How could I do this?

Edit: This probably involves two steps: change the currently active cell, then enter edit mode.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:08:51+00:00Added an answer on May 26, 2026 at 1:08 pm

    If you mean ‘activate the edit mode for the currently active cell’, then you should probably do like this:

    MyDBGrid.EditorMode := True;
    

    Activating a particular cell can be done either via SelectedIndex:

    MyDBGrid.SelectedIndex := 2;  { or maybe MyDBGrid.SelectedIndex + 1 }
    

    or via SelectedField:

    MyDBGrid.SelectedField := MyDataSet.FieldByName('Name');
    

    To determine which cell is under the mouse cursor at the moment, you can use MouseCoord, which returns a TGridCoord record holding the coordinates of the cell under the cursor. The TGridCoord.X field can be used directly to set the grid’s active column.

    var
      Cell: TGridCoord;
    
    ...
    
    Cell := MyDBGrid.MouseCoord(X, Y);
    MyDBGrid.SelectedIndex := Cell.X;
    

    Setting the row is trickier, and so far the only way I could find involves the so called protected hack, the method of accessing protected properties and methods of a class. And it’s the TDBGrid class that we need to ‘hack’.

    Basically, you declare an empty descendant of TDBGrid, like this:

    type
      THackDBGrid = class(TDBGrid);
    

    Then, when you need to access a protected property or method, you simply cast the instance of a standard class (MyDBGrid in this case) to the ‘hacked’ type (THackDBGrid):

    … THackDBGrid(MyDBGrid).protected_property_or_method …
    

    The item we are interested in is the Row property. It returns the Y coordinate of the active row. We need to know it to determine the difference between the active row and the one under the cursor, so we could then move the underlying dataset’s record pointer accordingly. Here’s how:

    MyDataSet.MoveBy(Cell.Y - THackDBGrid(MyDBGrid).Row);
    

    The Row value is not absolute: it is relative to the visible top row, but so is TGridCoord.Y, so the difference between the two corresponds to the difference between the data rows in the underlying dataset.

    One thing that I’d like to stress: this protected hack method should be used discreetly. Protected items are protected for a reason. So, if you can avoid it, please do so. And if you can’t (there’s no other way or it helps you to do things much more easily), please remember to refrain from changing anything directly using protected hack. I mean, it might be all right, but generally you never know for sure. You can see that I only used the method to read the protected contents, I didn’t change anything directly. The object’s state was eventually changed, but that was the result of a standard mechanism triggered by the MoveBy method.

    You can read more about protected hack here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I only want a method to activate if the pixel that is clicked is
On my website I want a small flash banner which the user can activate
When a user goes to edit a number, I want to format a number
We want to activate a process if the user does not interact for 2
The design of the UITableView is something like this: I want to make my
I want to activate a search textbox when the user starts to type something
I want to activate the jQueryUI button widget on a given selector, lets say
i'm using MAMP and want to activate xdebug. i've uncomment the following row in
I have a sharepoint event handler which I want to activate for a single
I am doing a movieplayer application and I want to activate certain settings about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.