We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to get the list item from ItemHolding event

Hi,

I'm wondering if there is a possibility to get the list item from a ItemHolding event? The ItemHoldingEventArgs contains a reference to the ItemData, the ItemType and the point on which the holding gesture took place. But there is no reference to the list item itself. Neither there are CurrentItem or SelectedItem set (if they were not set already).

Setting SelectionGesture property is not eligible, because the list item should not be selected on this event.

Kind regards

5 Replies

DB Dinesh Babu Yadav Syncfusion Team June 18, 2019 08:47 AM UTC

Hi Bkind, 
 
Thank you for contacting Syncfusion support. 
 
Unfortunately, we are unable to understand the term “get the list item in the ItemHolding event”, if your requirement is to get the underlying data object as like data holding in the SelectedItem or CurrentItem properties, then we would like to let you know that the ItemData argument in the ItemHolding event holds the underlying data object only or if your requirement is about to get the respected listview item or its content in the event, then please refer the below code snippet. 
 
Code Example[C#]: 
VisualContainer Container = listView.GetVisualContainer(); 
 
private void ListView_ItemHolding(object sender, ItemHoldingEventArgs e) 
{ 
   //Represents the underlying data model object. 
   var datamodel = e.ItemData as BookInfo; 
   var item = Container.Children.FirstOrDefault(x => x.BindingContext == datamodel) as ListViewItem; 
   if (item != null) 
   { 
      //Represents the child element of listview item. 
      var templatecontent = item.Content; 
   } 
} 
 
For your reference, we have prepared the sample with above code example and you can download it from the below link. 
 
 
If your requirement is other than this, we suggest you to please explain the requirement in detail which would highly help us to analyze the requirement better and update you an appropriate solution. 
  
Please let us know if you require further assistance. 
 
Regards, 
Dinesh Babu Yadav 



BK bkind June 18, 2019 07:03 PM UTC

Hi and thank you,

that's exactly what I was looking for!
I should have mentioned ListViewItem, not just list item, which was a bit confusing, sorry.

So I get the ListViewItem which triggered the holding event.
Btw, would it be difficult to include a reference of the ListViewItem into the ItemHoldingEventArgs?

Kind regards


DB Dinesh Babu Yadav Syncfusion Team June 19, 2019 07:35 AM UTC

Hi Bkind, 
 
Thanks for the update. 
 
We would like to let you know that referencing the listview item in ItemHolding event argument is not a valid behavior. However, Can you please share your application scenario based on that we can suggest you a possible solution. 
 
Please let us know if you require further assistance. 
 
Regards, 
Dinesh Babu Yadav 



BK bkind June 23, 2019 09:00 PM UTC

Hi,

Of course, the scenario is quite simple. I have a SfListView showing more or less detailled shift information. The user can open an extended context menu (popup) via the ItemHolding gesture. The popup shall be automatically placed adjacent to the touched list item, either above or below. Therefore the popup must know the list item's position on the screen, or better: the XF element that has been touched - this way the position calculation is encapsulated within the popup. No further usage is made of the reference, it will be released as soon as the position has been calculated.

Kind regards


JP Jagadeesan Pichaimuthu Syncfusion Team June 24, 2019 09:18 AM UTC

Hi Bkind, 
  
We would like to inform you that you can achieve your requirement using the bounds of the ItemData from e.Position.X and e.Position.Y. We already have published the sample regarding your requirement in our UG documentation, you can refer the model sample to display the pop-up menu by accessing the touch position in the item based on Position property from ItemHolding event from below link. 
  
  
Please let us know if you have any further queries. 
  
Regards, 
Jagadeesan   


Loader.
Up arrow icon