BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

OnDraw and DBComboBox ...

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Using
View previous topic :: View next topic  
Author Message
Nick Rambarransingh
Guest





PostPosted: Tue Oct 21, 2003 1:35 am    Post subject: OnDraw and DBComboBox ... Reply with quote



Good Day All,

I tried for many weeks to get a reasonable answer on this. I did get a
partial answer, but, that only lead to an already know problem. As a result, I
want to try and report it here. You can fin this post in the datasnap group,
under the same subject, around early Oct.

I have a DBComboBox looking at an Int field in a Table. In the
ComboBox->items, I have the ASCII strings "APPLE", "ORANGE", "BANANA", "PEACH"
.... I would like to show the User "APPLE" instead of the integer 1.
I followed someones advice and have been trying the OnDraw event, but have not
been completely successful. I usually run into the "APPLE" is not an int. Now
I am at the point, where I am not getting that error any more, but, I am not
getting anything in the text area.


Any help would be appreciated.

Thanks,
Nick

//---------------------------------------------------------------------------
void __fastcall TGenCodesDBListFrame::ComboBoxDrawItem(TWinControl *Control,
int Index, TRect &Rect, TOwnerDrawState State)
{

//Verify the ComboBox has been initialized.
if (ComboBox->DataField.Length() < 1)
return;

TCanvas *pCanvas = ComboBox->Canvas;

if( State.Contains(odSelected) )
{
pCanvas->Brush->Color = clHighlight;
pCanvas->Font->Color = clHighlightText;

//Draw the Text in the edit box, and, set the field value
if (ComboBox->DataSource->State == dsEdit)
if (ComboBox->DataField.Length() > 0)
{
ComboBox->Text = ComboBox->Items->Strings[Index];
ComboBox->Field->AsInteger = ComboBox->ItemIndex;
}

}
else
{
pCanvas->Brush->Color = ComboBox->Color;
pCanvas->Font->Color = ComboBox->Font->Color;
}

pCanvas->FillRect(Rect);
pCanvas->TextRect(Rect, Rect.Left + 2, Rect.Top,
ComboBox->Items->Strings[Index]);

if( State.Contains(odFocused) && !State.Contains(odNoFocusRect ) )
pCanvas->DrawFocusRect(Rect);

}
//---------------------------------------------------------------------------
Back to top
Guest






PostPosted: Mon Oct 27, 2003 8:44 pm    Post subject: Re: OnDraw and DBComboBox ... Reply with quote



How about using a calcfield for that column? The calc field would translate
the integer into the string and display. You could use the itemIndex
property of the combo to set the data field too. Trivial.


"Nick Rambarransingh" <NRambarransingh (AT) Videotron (DOT) ca> wrote

Quote:
Good Day All,

I tried for many weeks to get a reasonable answer on this. I did get a
partial answer, but, that only lead to an already know problem. As a
result, I
want to try and report it here. You can fin this post in the datasnap
group,
under the same subject, around early Oct.

I have a DBComboBox looking at an Int field in a Table. In the
ComboBox->items, I have the ASCII strings "APPLE", "ORANGE", "BANANA",
"PEACH"
... I would like to show the User "APPLE" instead of the integer 1.
I followed someones advice and have been trying the OnDraw event, but
have not
been completely successful. I usually run into the "APPLE" is not an int.
Now
I am at the point, where I am not getting that error any more, but, I am
not
getting anything in the text area.


Any help would be appreciated.

Thanks,
Nick


//--------------------------------------------------------------------------

-
Quote:
void __fastcall TGenCodesDBListFrame::ComboBoxDrawItem(TWinControl
*Control,
int Index, TRect &Rect, TOwnerDrawState State)
{

//Verify the ComboBox has been initialized.
if (ComboBox->DataField.Length() < 1)
return;

TCanvas *pCanvas = ComboBox->Canvas;

if( State.Contains(odSelected) )
{
pCanvas->Brush->Color = clHighlight;
pCanvas->Font->Color = clHighlightText;

//Draw the Text in the edit box, and, set the field value
if (ComboBox->DataSource->State == dsEdit)
if (ComboBox->DataField.Length() > 0)
{
ComboBox->Text = ComboBox->Items->Strings[Index];
ComboBox->Field->AsInteger = ComboBox->ItemIndex;
}

}
else
{
pCanvas->Brush->Color = ComboBox->Color;
pCanvas->Font->Color = ComboBox->Font->Color;
}

pCanvas->FillRect(Rect);
pCanvas->TextRect(Rect, Rect.Left + 2, Rect.Top,
ComboBox->Items->Strings[Index]);

if( State.Contains(odFocused) && !State.Contains(odNoFocusRect ) )
pCanvas->DrawFocusRect(Rect);

}

//--------------------------------------------------------------------------

-



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Using All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.