Containing hidden "objects" in ListviewItem, with inheritance?
I have a listview control, and it's data refreshing continously. I'd like to 'put' an XElement into a row, so I if e.g. double-click on the row, the double-click would call a method, with the 'hidden' xelement parameters.
I hope I started to solve it, the debugger doesn't show any errors, but I don't know how to reach the XElement-typo element from the row.
Here is the relevant part of my code:
ListViewItem item = new ListViewItem();
item = listBighit.Items.Add(new Offer (sor[0].ToString(),xml1,xml2));
item.SubItems.Add(sor[1].ToString());
item.SubItems.Add(sor[2].ToString());
item.SubItems.Add(sor[3].ToString());
item.SubItems.Add(sor[4].ToString());
item.SubItems.Add(sor[5].ToString());
publ开发者_运维技巧ic class Offer : ListViewItem
{
protected XElement _xml1;
protected XElement _xml2;
public Offer(string penznem, XElement xml1, XElement xml2)
{
this.xmlAddress1 = xml1;
this.xmlAddress2 = xml2;
base.Text = penznem;
}
public XElement xmlAddress1
{ get { return this._xml1; } set { this._xml1 = value; } }
public XElement xmlAddress2
{ get { return this._xml2; } set { this._xml2 = value; } }
}
I hope some guru can help me out :) Thank you!
ListViewItem item = new ListViewItem();
item = listBighit.Items.Add(new Offer (sor[0].ToString(),xml1,xml2));
The first line doesn't do anything. I imagine what you really want to do is create an Offer, not a ListViewItem:
Offer item = new Offer(...);
item.SubItems.Add(...);
// etc..
listBighit.Items.Add(item);
Then when you need to retrieve an item from the ListView, cast it back to an Offer:
Offer first = (Offer)listBighit.Items[0];
精彩评论