Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where in DBGrid am I?

Status
Not open for further replies.

JoeNg

Programmer
Apr 17, 2001
174
US
I have DBGrid with a Paradox table, how can I return the field value where the cursor is?

Thanks

Joe
 
Joe,

Try something like dbGrid1.SelectedField.AsString.

Hope this helps...

-- Lance
 
Lance,

Thanks!

Now, How about getting all field values of the same records?
Something like CopyToArray in Pdox?

Joe
 
When you move in the grid, the underlaying table (connected with DataSource) follows your movements, thus you can reach the actual record easily via persistent fields (Table1Field1.Value) or Table1.Fiels[x].Value or Table1.FieldByName('xxx').Value
All fields:
with Table1 do
for i:=0 to Fields.Count-1 do
// do anything with Fields.Value

Otto
 
Joe,

Adding to Joe's comment, you can do this without hardcoding the reference to your actual table (e.g. you're working with a dataModule and want to keep the code on your form generic:

Code:
with DbGrid1.DataSource.Dataset do
   for siCounter := 0 to ( Fields.Count - 1 ) do
      dblTotal := Fields[ siCounter ].asFloat;

This is particularly hand, for it lets you create general code in your "data viewers" and makes it easier to reuse later.

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top