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

double click on a database grid 1

Status
Not open for further replies.

hennep

Programmer
Dec 10, 2000
429
I want to select a record in a database grid (by double clicking) and use the data in my code.
How do I know which record is selected, what property of the grid holds the active cell ?
 
the proper record is selected just by a single click on the record. this becomes the active record or selected record.
look for a highlited field or the far left colum.
the double click method will respond by posibly copying each field to a separate buffer. If yoiu are selecting an individual field for processing.

Look in "SelectedField" in the helpfiles
under TDBGrid properties.

any action upon the table will be to the presently active record.

table1->Edit ();
table1->fields [0] = "field1";
table1->fields [1] = "field2";
table1->Post ();

this action is upon the curently active record.

x = table1->RecNo;

x is the value of the curently active record were 0 =
the first record and 1 = the second record. Or does it start with 1 first. your task for the day is to find out which.

happy turkey!!!!!!!!!!!!!!!!!!!!!!!
 
To select the whole record I needed to set the dgRowSelect and dgMultiSelect options.
I didn't notice this before, the options are not expanded by default.

void __fastcall TfrmAdres::GridDblClick(TObject *Sender) {
if( Grid->SelectedRows->Count > 0 ) {
TDataSet *pDS = Grid->DataSource->DataSet;
for( int i=0; i < Grid->SelectedRows->Count && i<1; i++ ) {
pDS->GotoBookmark((void *)Grid->SelectedRows->Items.c_str());
strcpy( frmMain->Num->email, pDS->Fields->Fields[7]->AsString.c_str() );
strcpy( frmMain->Num->fax, pDS->Fields->Fields[3]->AsString.c_str() );
}
}
}

 
italics again

WHY DONT THEY SWITCH THIS STUPID OPTION OFF IN A CPP FORUM ?

this line was not complete:

pDS->GotoBookmark((void *)Grid->SelectedRows->Items[ i ].c_str());
 
the record is already set as active when you click on it in the grid. once you click on the grid all you have to do is copy the fields.

surveynumber = table1->Fields [0]->AsInteger;
custnumber = table1->Fields [1]->AsInteger;

It is already selected. you asked how do you know which
record is selected. Well you just clicked on it. You
could check the RecNo but I see no reason unles you have a
need for say the 4th record in the table were you would set

table1->RecNo = 4;
 
hennep,
[tab]WHY DONT THEY SWITCH THIS STUPID OPTION OFF IN A CPP FORUM ? You can, just uncheck the Process TGML at the bottom of &quot;Your Reply&quot; James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top