Forum  Commercial Foru...  Commercial Foru...  Reference Current Row In ListView Button
Previous Previous
 
Next Next
New Post 1/12/2012 7:30 PM
Resolved
  derekmhart@yahoo.com
717 posts
1st Level Poster


Reference Current Row In ListView Button 

I have a listview column where I have added a button (to a column of type control). The button has a handler attached to it, and I need to reference the row the button is in. How can I do this?

I cannot use lst.SelectedItem.SubItems(1).Text because the row may not be selected, only the button in it clicked.

 
New Post 1/13/2012 12:06 AM
  JamesC
634 posts
www.redcastle.co.uk
1st Level Poster




Re: Reference Current Row In ListView Button 

Hi there, a simple way is: when adding the button to the ListViewItem set the ListViewItem as the Tag property of the button.

ListViewItem itmX = new ListViewItem("Hello");

Button btn = new Button();

btn.Text = "World";

btn.Tag = itmX;

itmX.SubItems.Add(btn);

 

 
New Post 1/13/2012 8:33 AM
  derekmhart@yahoo.com
717 posts
1st Level Poster


Re: Reference Current Row In ListView Button 

OK, I can store the object in the tag. But how can I use that to remove the row, for example. I know I can remove a row like this:

lst.Items(x).Remove()

... where x is the index... but how do I use that object in the tag to remove the row?

 
New Post 1/13/2012 9:21 AM
Accepted Answer 
  JamesC
634 posts
www.redcastle.co.uk
1st Level Poster




Re: Reference Current Row In ListView Button 

in your button_click event

Button btn = sender as Button;

LsitViewItem itmX  = btn.Tag as ListViewItem

then any of the following Remove methods:

lst.Items[itmX.Index].Remove();

lst.Items.Remove(itmX);

lst.Items.RemoveAt(itmX.Index);

Cheers james

 
New Post 1/13/2012 10:19 AM
  derekmhart@yahoo.com
717 posts
1st Level Poster


Re: Reference Current Row In ListView Button 

Thanx!

 
Previous Previous
 
Next Next
  Forum  Commercial Foru...  Commercial Foru...  Reference Current Row In ListView Button
Assessment Bottom
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS