Board index » cppbuilder » How to change the background color of all TDBEdit controls of a form

How to change the background color of all TDBEdit controls of a form


2004-08-02 06:55:55 PM
cppbuilder113
I want to put another background color when the user is in edit mode.
I've tried in the OnClick event of the TDBNavigator:
-------------------------------------------------------------
void __fastcall TGeneralF::DBNavigatorClick(TObject *Sender,
TNavigateBtn Button)
{
int i;
switch (Button)
{
case nbEdit:
for ( i = 0; i < GeneralF->ControlCount; i++)
{
if ( GeneralF->Controls[i]->ClassNameIs("TDBEdit") )
{
GeneralF->Controls[i]->Color = clAqua;
}
}
break;
default:
for ( i = 0; i < GeneralF->ControlCount; i++)
{
if ( GeneralF->Controls[i]->ClassNameIs("TDBEdit") )
{
GeneralF->Controls[i]->Color = clWhite;
}
}
}
}
//---------------------------------------------------------------------------
But I get a compiler error:
[C++ Error] FGeneral.cpp(75): E2247 'TControl::Color' is not accessible
?Does anyone know a method to do this ?
Thank you.
 
 

Re:How to change the background color of all TDBEdit controls of a form

Maybe something like this:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
for ( int i = 0; i < Form1->ComponentCount; i++ )
{
TDBEdit* ED = dynamic_cast<TDBEdit*>( Form1->Controls[i] );
if ( ED ) ED->Color = clCream;
}
}
Best regards,
Vladimir Stefanovic
 

Re:How to change the background color of all TDBEdit controls of a form

Quote
I want to put another background color when
the user is in edit mode. I've tried in the OnClick
event of the TDBNavigator
Generaly, it's not good idea to use TDBNavigator
to detect change of the DataSource's state. Sometimes
you can change the state by keyboard, for example in
DBGrid when using arrow keys...
It's better to use OnStateChange() and catch:
int State = SomeDB->SomeQry->State; // or SomeTbl
switch ( State )
{
case dsInactive:
// ...
// etc.
Best regards,
Vladimir Stefanovic
 

{smallsort}