been selected or double clicked I would like to change the color of that
one item. Can someone please post a snip?
TIA,
Kim
The following code will change a ListBox's item to red if
double-clicked...
//in header...
bool HasBeenSelected[1000];
//in source...
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//Initialize our flags
for (int index = 0; index < 1000; index++) HasBeenSelected[index] =
false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int
Index,
TRect &Rect, TOwnerDrawState State)
{
//Eliminate artifacts
ListBox1->Canvas->FillRect(Rect);
//Check to see if Index has been selected
if (HasBeenSelected[Index] == true)
{
//Color the text
ListBox1->Canvas->Font->Color = clRed;
}
//Check for selection rectangle
// and color font white so it's visible
else if (State.Contains(odSelected))
ListBox1->Canvas->Font->Color = clWhite;
else ListBox1->Canvas->Font->Color = clBlack;
ListBox1->Canvas->TextOut(Rect.Left + 1, Rect.Top,
ListBox1->Items->Strings[Index]);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1DblClick(TObject *Sender)
{
//Set the flag for double-clicked item to true
HasBeenSelected[ListBox1->ItemIndex] = true;
}
Damon Chandler
dm...@cornell.edu
Damon Chandler <dm...@cornell.edu> schreef in artikel
<36E56832...@cornell.edu>...
[ explanation snipped ]
> The following code will change a ListBox's item to red if
> double-clicked...
>
> //in header...
> bool HasBeenSelected[1000];
>
>
> //in source...
>
//--------------------------------------------------------------------------
-
> __fastcall TForm1::TForm1(TComponent* Owner)
> : TForm(Owner)
> {
> //Initialize our flags
> for (int index = 0; index < 1000; index++) HasBeenSelected[index] =
> false;
> }
Hmm, have you thought about to use the TListBox->Items->Objects[index]
property to set the selection flags? That way you can get rid of the
HasBeenSelected array...
Just my two cents...;-))
> Damon Chandler
--
Greetings from overcast Amsterdam
Jan
email: bij...@worldonline.nl
http://home.worldonline.nl/~bijster