 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ercan MUTLU Guest
|
Posted: Sun May 15, 2005 4:51 pm Post subject: Inserting Icons from ImageList to ListBox PROBLEM !.. |
|
|
On OwnerDraw Method : I inserted the icons on spesific Index
BUT the problem is When I Click on diffrent ItemIndex ,previous
icons dissapers !...
THE OTHER PROBLEM IS
when I change more then ONE ITEMS ICONS on listBox
then previosly is dissapired too.
What is the way that to rememmber more then 1 different ICONS
on OwnerDraw method...? ....
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sun May 15, 2005 5:33 pm Post subject: Re: Inserting Icons from ImageList to ListBox PROBLEM !.. |
|
|
"Ercan MUTLU" <mutlue (AT) mail (DOT) com> wrote
| Quote: | On OwnerDraw Method : I inserted the icons on spesific Index
BUT the problem is When I Click on diffrent ItemIndex ,previous
icons dissapers !...
|
You probably aren't drawing the icons correctly to begin with. Please show
your actual code.
Gambit
|
|
| Back to top |
|
 |
Ercan MUTLU Guest
|
Posted: Mon May 16, 2005 11:49 am Post subject: Re: Inserting Icons from ImageList to ListBox PROBLEM !.. |
|
|
The code is above (OnDraw Method)
----------------------
ListBox1->Canvas->FillRect(Rect);
ImageList1->Draw(ListBox1->Canvas, Rect.Left + 2, Rect.Top,1, true);
// normal icon
if(Bul!=-1) // Bul is the Item on the ListBox to be showed in
different // ICON (int value) SEE the ButtonClick method
{
if(Index==Bul) ImageList1->Draw(ListBox1->Canvas, Rect.Left +
2,Rect.Top,2, true);// desired Icon
}
ListBox1->Canvas->TextOut(Rect.Left + ImageList1->Width + 4,Rect.Top,
ListBox1->Items->Strings[Index]);
-----------------------------------------
ON Button1Click Method
------------------------
Bul=Edit1->Text.ToInt(); // the ItemIndex I wish to change the Icon.
ListBox1->ItemIndex=Bul; // I did this to change the Icon imediatly when
// I click button. Without this, it dont
// changes the Icon imadiatly,unless i click on
// the listbox
---------------------
When I write the number of the ItemIndex in Edit1, "Bul" assign this
number when I Click The Button1 .
Then ,the desired Icon changes.
Its Works ! ..... BUT ONLY to ONE Item on the ListBox !..
If you choose another ItemIndex then previous Icon changes to normal
state. Because "Bul" CHANGES.
What is the way to keep the Number of previosly selected Items?..
(without making an array of int ..)Becaouse I have 100000 of structure
to be showed. should I have to make array of integer(100000) to keep
this Items number?
I hope you undertand me...
Thanks !...
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon May 16, 2005 5:25 pm Post subject: Re: Inserting Icons from ImageList to ListBox PROBLEM !.. |
|
|
"Ercan MUTLU" <mutlue (AT) mail (DOT) com> wrote
| Quote: | If you choose another ItemIndex then previous Icon changes
to normal state.
|
As it should, because that is how you designed your code to operate.
| Quote: | What is the way to keep the Number of previosly selected Items?..
(without making an array of int ..)Becaouse I have 100000 of structure
to be showed. should I have to make array of integer(100000) to keep
this Items number?
|
Yes, you must manually store all of the desired indexes that you want to
display differently. If you don't want to use an array, then the easiest
way is to utilize the ListBox's existing Objects[] array instead. You can
then either:
1) store a flag that indicates the item should be drawn differently:
void __fastcall TForm1::AddFlagButtonClick(TObject *Sender)
{
int index = Edit1->Text.ToIntDef(-1);
if( index > -1 )
{
ListBox1->Items->Objects[index] = reinterpret_cast<TObject*>(1);
ListBox1->Invalidate();
}
}
void __fastcall TForm1::RemoveFlagButtonClick(TObject *Sender)
{
int index = Edit1->Text.ToIntDef(-1);
if( index > -1 )
{
ListBox1->Items->Objects[index] = reinterpret_cast<TObject*>(0);
ListBox1->Invalidate();
}
}
void __fastcall TForm1::ListBox1DrawItem(TWinControl* Control, int
Index, const TRect &Rect, TOwnerDrawState State)
{
if( State.Contains(odSelected) )
{
ListBox1->Canvas->Brush->Color = clHighlight;
ListBox1->Canvas->Font->Color = clHighlightText;
}
else
{
ListBox1->Canvas->Brush->Color = ListBox1->Color;
ListBox1->Canvas->Font->Color = ListBox1->Font->Color;
}
ListBox1->Canvas->FillRect(Rect);
int IsDifferent =
reinterpret_cast<int>(ListBox1->Items->Objects[Index]);
ImageList1->Draw(ListBox1->Canvas, Rect.Left + 2, Rect.Top,
(IsDifferent == 1) ? 2 : 1, true);
ListBox1->Canvas->TextRect(Rect, Rect.Left + ImageList1->Width + 4,
Rect.Top, ListBox1->Items->Strings[Index]);
}
1) store the actual icon index instead:
void __fastcall TForm1::NormalIconButtonClick(TObject *Sender)
{
int index = Edit1->Text.ToIntDef(-1);
if( index > -1 )
{
ListBox1->Items->Objects[index] = reinterpret_cast<TObject*>(1);
ListBox1->Invalidate();
}
}
void __fastcall TForm1::DifferentIconButtonClick(TObject *Sender)
{
int index = Edit1->Text.ToIntDef(-1);
if( index > -1 )
{
ListBox1->Items->Objects[index] = reinterpret_cast<TObject*>(2);
ListBox1->Invalidate();
}
}
void __fastcall TForm1::ListBox1DrawItem(TWinControl* Control, int
Index, const TRect &Rect, TOwnerDrawState State)
{
if( State.Contains(odSelected) )
{
ListBox1->Canvas->Brush->Color = clHighlight;
ListBox1->Canvas->Font->Color = clHighlightText;
}
else
{
ListBox1->Canvas->Brush->Color = ListBox1->Color;
ListBox1->Canvas->Font->Color = ListBox1->Font->Color;
}
ListBox1->Canvas->FillRect(Rect);
int IconIndex =
reinterpret_cast<int>(ListBox1->Items->Objects[Index]);
ImageList1->Draw(ListBox1->Canvas, Rect.Left + 2, Rect.Top,
IconIndex, true);
ListBox1->Canvas->TextRect(Rect, Rect.Left + ImageList1->Width + 4,
Rect.Top, ListBox1->Items->Strings[Index]);
}
Gambit
|
|
| Back to top |
|
 |
|
|
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
|
|