ListBoxItem->ItemData->Bitmap

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

ListBoxItem->ItemData->Bitmap

Postby Lena » Tue Dec 13, 2016 3:00 am

Hi.
How to add a picture to the ListBox?
I do not see the picture.
Code: Select all
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  std::unique_ptr<TMemoryStream> WelcomeINI(new TMemoryStream());
  try
   {
   IdHTTP1->Get(L"http://welcome.um.la/myimg/11.png", WelcomeINI.get());
   WelcomeINI->Position = 0;
   }
   catch(...)
      {
       WelcomeINI->LoadFromFile("72x72.png");
         WelcomeINI->Position = 0;
      }


     ListBox1->BeginUpdate();
      TListBoxItem *ListBoxItem;
     TListBoxGroupHeader *ListBoxGroupHeader;
     ListBoxGroupHeader = new TListBoxGroupHeader(ListBox1);
     ListBoxGroupHeader->Text = L"ONE";
     ListBox1->AddObject(ListBoxGroupHeader);

     ListBoxItem = new TListBoxItem(ListBox1);
     ListBoxItem->Text = L"Test1";
     ListBoxItem->ItemData->Bitmap->LoadFromStream(WelcomeINI.get());
     ListBox1->AddObject(ListBoxItem);
     ListBox1->EndUpdate();
}
Lena
BCBJ Master
BCBJ Master
 
Posts: 470
Joined: Sun Feb 06, 2011 1:28 pm

Re: ListBoxItem->ItemData->Bitmap

Postby rlebeau » Tue Dec 13, 2016 4:38 pm

Lena wrote:I do not see the picture.


Per this tutorial:

Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)

Each Item on a ListBox component can contain Bitmap data, as an Icon, through the ItemData.Bitmap property
...
In order to view the Icon, you must select a StyleLookup which supports the Bitmap property. Change the StyleLookup property to listboxitemleftdetail.


Are you using a Style that supports displaying the Bitmap?
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1408
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: ListBoxItem->ItemData->Bitmap

Postby Lena » Wed Dec 14, 2016 4:45 am

I do not see the picture.
Code: Select all
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  std::unique_ptr<TMemoryStream> WelcomeINI(new TMemoryStream());
  try
   {
   IdHTTP1->Get(L"http://welcome.um.la/myimg/11.png", WelcomeINI.get());
   WelcomeINI->Position = 0;
   }
   catch(...)
      {
       WelcomeINI->LoadFromFile("72x72.png");
         WelcomeINI->Position = 0;
      }


     ListBox1->BeginUpdate();
          TListBoxItem *ListBoxItem;
     TListBoxGroupHeader *ListBoxGroupHeader;
     ListBoxGroupHeader = new TListBoxGroupHeader(ListBox1);
     ListBoxGroupHeader->Text = L"ONE";
     ListBox1->AddObject(ListBoxGroupHeader);

     ListBoxItem = new TListBoxItem(ListBox1);
     ListBoxItem->StyleLookup = L"listboxitemdetaillabel";
          ListBoxItem->Height = 72;
     ListBoxItem->Text = L"Test1";
     ListBoxItem->ItemData->Bitmap->LoadFromStream(WelcomeINI.get());
     ListBox1->AddObject(ListBoxItem);
     ListBox1->EndUpdate();
}
Lena
BCBJ Master
BCBJ Master
 
Posts: 470
Joined: Sun Feb 06, 2011 1:28 pm

Re: ListBoxItem->ItemData->Bitmap

Postby rlebeau » Wed Dec 14, 2016 9:53 am

Lena wrote:I do not see the picture.


Do you have a TStyleBook in your project?

Did you verify that the stream has a valid image in it? Did you verify that LoadFromStream() is successful? It DOES NOT raise an exception on failure.

TBitmap remains unchanged if Stream uses an unsupported image format or is not actually an image. LoadFromStream does not raise any errors in this case.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1408
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: ListBoxItem->ItemData->Bitmap

Postby Lena » Thu Dec 15, 2016 2:12 am

Sorry I found my mistake
ListBoxItem->StyleLookup = L"listboxitemleftdetail";
Lena
BCBJ Master
BCBJ Master
 
Posts: 470
Joined: Sun Feb 06, 2011 1:28 pm


Return to Technical

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 5 guests