[ListView]identify an element

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

[ListView]identify an element

Postby Lena » Tue Oct 10, 2017 1:52 am

Hi.
I have an element TImageObjectAppearance in which the picture with a plus is loaded. There is a TTextObjectAppearance element that I plan to use as a counter. Ie clicked on the TImageObjectAppearance element and then added +1 to the TTextObjectAppearance element. I do not know how to implement this?
Details on the picture. (ItemAppearance=DynamicAppearance).
Thanks.

Code: Select all

void __fastcall TForm1::ListView1ItemClickEx(TObject * const Sender, int ItemIndex,
        const TPointF &LocalClickPos, TListItemDrawable * const ItemObject)

{

 if(ItemObject == NULL)
  {
   return;
  }

 if(ItemObject->Name == L"add" && ItemObject->InheritsFrom(__classid(TListItemImage)))
  {
   //how found TTextObjectAppearance with name TextCount?

  }

}
Attachments
list.jpg
list.jpg (44.02 KiB) Viewed 740 times
Lena
BCBJ Master
BCBJ Master
 
Posts: 525
Joined: Sun Feb 06, 2011 1:28 pm

Re: [ListView]identify an element

Postby Lena » Fri Oct 13, 2017 8:11 am

I try:
Code: Select all
void __fastcall TForm1::ListView1ItemClickEx(TObject * const Sender, int ItemIndex,
        const TPointF &LocalClickPos, TListItemDrawable * const ItemObject)

{
 if(ItemObject == NULL)
  {
   return;
  }

  //press Add button
 if(ItemObject->Name == L"add" && ItemObject->InheritsFrom(__classid(TListItemImage)))
  {
   TListViewItem * item = ListView1->Items->operator [](ItemIndex);
   UnicodeString splus = item->Data[L"TextCount"].AsString();
   int plus = StrToInt(splus) + 1;
   item->Data[L"TextCount"] = TValue::From<UnicodeString>(IntToStr(plus));
  }

 //press Minus button
 if(ItemObject->Name == L"min" && ItemObject->InheritsFrom(__classid(TListItemImage)))
  {
   TListViewItem * item = ListView1->Items->operator [](ItemIndex);
   UnicodeString smin = item->Data[L"TextCount"].AsString();

   if(smin == "1")
   {
      return;
   }

   int min = StrToInt(smin) - 1;
   item->Data[L"TextCount"] = TValue::From<UnicodeString>(IntToStr(min));

  }
}


But the event ListView1ItemClickEx happens for everyone item.
I have 4 items. ListView1ItemClickEx fire 4 times... :(
Lena
BCBJ Master
BCBJ Master
 
Posts: 525
Joined: Sun Feb 06, 2011 1:28 pm

Re: [ListView]identify an element

Postby Lena » Fri Oct 13, 2017 8:21 am

It seems to work this terrible design...
Code: Select all
bool flag = true;

void __fastcall TForm1::ListView1ItemClickEx(TObject * const Sender, int ItemIndex,
        const TPointF &LocalClickPos, TListItemDrawable * const ItemObject)

{
 if(ItemObject == NULL)
  {
   return;
  }

  if(flag == true)
   {
     //press Add button
    if(ItemObject->Name == L"add" && ItemObject->InheritsFrom(__classid(TListItemImage)))
     {
      flag = false;
      TListViewItem * item = ListView1->Items->operator [](ItemIndex);
      UnicodeString splus = item->Data[L"TextCount"].AsString();
      int plus = StrToInt(splus) + 1;
      item->Data[L"TextCount"] = TValue::From<UnicodeString>(IntToStr(plus));
     }

    //press Minus button
    if(ItemObject->Name == L"min" && ItemObject->InheritsFrom(__classid(TListItemImage)))
     {
      flag = false;
      TListViewItem * item = ListView1->Items->operator [](ItemIndex);
      UnicodeString smin = item->Data[L"TextCount"].AsString();

      if(smin == "1")
      {
         return;
      }

      int min = StrToInt(smin) - 1;
      item->Data[L"TextCount"] = TValue::From<UnicodeString>(IntToStr(min));

     }

   }//end flag
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ListView1ItemClick(TObject * const Sender, TListViewItem * const AItem)

{
 flag = true;
}
//---------------------------------------------------------------------------
Lena
BCBJ Master
BCBJ Master
 
Posts: 525
Joined: Sun Feb 06, 2011 1:28 pm


Return to Technical

Who is online

Users browsing this forum: Bing [Bot] and 16 guests

cron