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

Move to the end of a TDBGrid

Status
Not open for further replies.

ColTomb

Programmer
Oct 9, 2005
10
US
1. I have a TDBGrid that loads a bunch of records. When it's done, it shows the first record at the top of the window. I wish to code it to move to the last record in the list. I could either set the focus on the last record or move the scroll bar. Suggestions ?

2. When I click on a row, how do I pull information from a specific cell (this is not your basic string grid) ?
 
1. I'm assuming that your DataSource and DataSet is set up. Also that you database is not unidirectional. To get to your last read, youe grid needs to calls it DataSource which in turn calls its DataSet.
Code:
DBGrid1->DataSource->DataSet->Last();

2. I get back you you on this.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Sorry, I had to fix a problem. On #2, again I assume the same thing as I did in #1. You can use the grid's underlying data set.
Code:
int X = DBGrid1->DataSource->DataSet->ActiveRecord;

Post back here is these don't work for you.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Sir,
Thanks for your assistance. #1 worked fine (you already knew that!).

For #2 I get a "not accessible" error. I've read the help on this error but I don't understand it.

 
OK, I misunderstood what you are doing. You are still going to use the DataSet to get each cell's individual data. The active row in the DBGrid will also be the active row in the DataSet. There are several ways to get this info. You can use ARRAYOFCONST, FieldValues, or FieldByName for example. Which you use is defined by preference, what you know about the data base (field name or location), or the database itself.

I personally prefer FieldByName since I know each field's name in a table. For example, suppose my table has three fields, Item, a string; ItemCount, an integer; and ItemCost, a floating point value.

Now suppose I click on an item on the DBGrid. I could obtain each field's (cell's) info like this:
Code:
AnsiString ItemStr = DataSet->FieldByName("Item")->AsString;
int ItemCountInt = DataSet->FieldByName("ItemCount")->AsInteger;
double ItemBucks = DataSet->FieldByName("ItemCost")->AsFloat;

Read and understand about DataSets. They will the the basis for all other data base components.

James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Sir,
Many thanks for the tutorial - it has opened up a whole lot of flexibility for me while I re-write my INVOICES program.

Last thing: how do you open the "CODE" window when you post a reply ?

Cheers !
 
Look at the Process TGML link just below the message box. There are a lot of options.

James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top