Page 1 of 1

ListBoxItem->ItemData->Bitmap

PostPosted: Tue Dec 13, 2016 3:00 am
by Lena
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();
}

Re: ListBoxItem->ItemData->Bitmap

PostPosted: Tue Dec 13, 2016 4:38 pm
by rlebeau
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?

Re: ListBoxItem->ItemData->Bitmap

PostPosted: Wed Dec 14, 2016 4:45 am
by Lena
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();
}

Re: ListBoxItem->ItemData->Bitmap

PostPosted: Wed Dec 14, 2016 9:53 am
by rlebeau
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.

Re: ListBoxItem->ItemData->Bitmap

PostPosted: Thu Dec 15, 2016 2:12 am
by Lena
Sorry I found my mistake
ListBoxItem->StyleLookup = L"listboxitemleftdetail";