#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    42
    Rep Power
    1

    How to get focused or selcted row data from DBGrid/ DBAdvGrid


    How to get focused or selected row data from DBGrid or DBAdvGrid as shown in figure below ?
    Is there any method at DBGrid/ DBAdvGrid which enables us to get selected data or do we have to use Dataset associated with DBGrid/DBAdvGrid



    I already tried to use

    Code:
    edtLabel.Text := DBAdvGrid1.DataSource.DataSet.FieldByName('label').Value;
    In above figure it is expected to return 3rd row result but it is returning first row result with this method

    And

    Code:
    edtLabel.Text := MainFrm.FrmMain.DBAdvGrid1.Fields[3].Value;
    This method is returning error.

    Is there any way to extract data from focused row as shown in above figure (Focused row no 3) ?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    355
    Rep Power
    7
    Your first attempt should work, I would change .Value to .AsString. Perhaps you attached your code to the wrong event (such as OnCreate - When the first record in selected). Attach the code to your Query's AfterScroll event.

    edtLabel.Text := DBAdvGrid1.DataSource.DataSet.FieldByName('label').AsString;

    Comments on this post

    • ninadgac agrees
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    42
    Rep Power
    1
    Yes it is working perfectly with Querys AfterScroll event.
    Amazing solution...

IMN logo majestic logo threadwatch logo seochat tools logo