Board index » delphi » DBGRID Question

DBGRID Question

Hello,

    Im using a DBGRID to display results from an SQL query that
    my application issues, however I am having problem with two
    simple/fundamental areas - and I would be exceptionally greatful
    if you could help.

    1)    When the DBGRID is displayed I allow the user to select a
            row from within the GRID.  I then need to extract the selected
row
            number from the GRID.  How do I obtain the selected ROW number?

    2)    Secondly I need to obtain the value stored within the first
column/field
            in the selected ROW.

    I have tried writing several approaches to achieve the above, but I
    am having problems - hence cant retreive the required data.

    I am actually writing the application in C++ Builder but I could'nt find
a
    C++ builder newsgroup. :(  I'd assume that the delphi source
code/components
    would operate in the same way that the C++ builder does.

    If you could supply any sample source code etc I would be very greatful.

    Best regards,

Spence

 

Re:DBGRID Question


I'm sorry to say that Row and Column are in the protected part of DBGrid
class

If you need to get both row and column values, then you need to subclass
DBGrid.

type
    TCheatDBGrid = class(TDBGrid);

to display DBGrid1 current column and row in a label, say Label1:

procedure TForm1.DBGrid1ColEnter(Sender: TObject)
begin
    Label1.Caption := Format('Col: %2d; Row: %2d',
[TCheatDBGrid(DBGrid1).Col, TCheatDBGrid(DBGrid1).Row]);
end;

Quote
"Spence" <nospam_spick...@lucent.com> wrote in message

news:8rtchg$bmr@nntpb.cb.lucent.com...
Quote
> Hello,

>     Im using a DBGRID to display results from an SQL query that
>     my application issues, however I am having problem with two
>     simple/fundamental areas - and I would be exceptionally greatful
>     if you could help.

>     1)    When the DBGRID is displayed I allow the user to select a
>             row from within the GRID.  I then need to extract the selected
> row
>             number from the GRID.  How do I obtain the selected ROW
number?

>     2)    Secondly I need to obtain the value stored within the first
> column/field
>             in the selected ROW.

>     I have tried writing several approaches to achieve the above, but I
>     am having problems - hence cant retreive the required data.

>     I am actually writing the application in C++ Builder but I could'nt
find
> a
>     C++ builder newsgroup. :(  I'd assume that the delphi source
> code/components
>     would operate in the same way that the C++ builder does.

>     If you could supply any sample source code etc I would be very
greatful.

>     Best regards,

> Spence

Other Threads