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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TDBGrid: Accessing cell/field values

Status
Not open for further replies.

gibben

Technical User
Jun 2, 2003
18
NZ
Hi there,

I am fairly new to delphi so please bear with me ....

I have an application that I am working on that has a TDBGrid that is querying an excel spreadsheet, I now want to access the individual data for use within the programme.

I am having problems with finding the correct properties to index a particular value by column and row.

eg:
Year | Jan | Feb | Mar
----------------------
2000 | 20 | 30 | 56
2001 | 43 | 76 | 09
2002 | 21 | 72 | 41

so if I wanted the value for feb - 2001 it would be indexed as column[3] row[2], however it appears the TDBGrid doesn't support this style ??

I can pull data in for a cell by using:
edit1.Text := excelgrid.Datasource.Dataset.Fields[1].AsString;

but can't find a way of specifying the row, can someone please enlighten me as to the correct context for accessing values in a particular cell.

Thanks in advance
 
Hi Gibben,

Try to think in terms of current row, being the current row in the dataset and the grid. You can change the row it using Dataset.Next, Dataset.Prior, Dataset.Locate.

Row number in a DBGrid is a concept that is kept hidden. If rows had scrolled off the top would you want the nth visible row, or the nth row from the start of the dataset? I agree row number is a natural way to approach a grid, especially if you are used to dealing with non-data aware grids, but try to think "dataset", rather than "grid" and plan your application that way.

One last point. Columns collection is zero based, so Feb is Columns[2] (unless you are showing the indicator column <g>). There is a property: excelGrid.Columns[3].Field.asString.

I'm not sure that I've answered your question excactly, but hopefully my ramble is of assistance.

Good luck
Simon
 
Yes thanks this did answer my question,

I am now getting my data in directly from the datasource and ignoring the grid ....

Thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top