Thread: DBgrid problem!
View Single Post
Old 08-01-2004, 10:39 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
Quote:
I'm trying to test if I find the record I select with this code (in a Button) :
Code:
bool record_found = false;

while(!DM->Query->Eof && !bool record_found)
{
     if(DBGrid->SelectedRows->CurrentRowSelected)
        {
            bool record_found = true;
        }
        DM->Query->Next();
}
Everytime, the first row don't seem to exist when I select it manually or not...
Looks like you're creating several instances of the record_found here, have you tried:
Code:
bool record_found = false;

while(!DM->Query->Eof && !record_found)
{
     if(DBGrid->SelectedRows->CurrentRowSelected)
        {
            record_found = true;
        }
        DM->Query->Next();
}
Since within the while loop the bool record_found will create a new instance of record_found that resides in the while scope, and won't intervene with the record_found declared outside the while scope.
Quote:
P.S. When I put the indicator to true, the "->" color is different when it's the first row...
What are you talking about?? a color changing when setting something to true, are you talking about the IDE you're developing in??
Quote:
P.S. I tried also "DBGrid->SelectedRows->Delete();" for deleting and even if I select only 1 row it delete ALL rows even if the "DBGrid->SelectedRows->Count" indicate that I selected only 1 row... Do these objects work propely or did I forget to do something?
It depends, if you have a flaw in your while loop, which makes it keep on going, then every row will eventualy be deleted.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote