i want store additional information listview item using custom class, can't seem work. i'm using code accomplish similar using listbox item. want same thing listview.
public class mylistboxitem public id string public rootfolder string public name string public info() string public text string public overrides function tostring() string return me.text end function end class i set properties this
private sub frmmain_load(byval sender system.object, byval e system.eventargs) handles mybase.load dim item new mylistboxitem item.text = "this test" item.rootfolder = "c:\test" item.id = "testid" item.name = "test item" item.info(0) = "some information" lstexample.items.add(item) end sub then can access these additional properties using this:
private sub lstexample_selectedindexchanged(byval sender system.object, byval e system.eventargs) handles lstexample.selectedindexchanged dim item mylistboxitem = ctype(lstexample.selecteditem, mylistboxitem) messagebox.show(item.id) messagebox.show(item.rootfolder) messagebox.show(item.name) messagebox.show(item.info(0)) end sub so question how can done listview? here tried:
public class mylistviewitem public id string public rootfolder string public name string public info() string public text string public overrides function tostring() string return me.text end function end class private sub frmmain_load(byval sender system.object, byval e system.eventargs) handles mybase.load dim item new mylistviewitem item.text = "this test" item.rootfolder = "c:\test" item.id = "testid" item.name = "test item" item.info(0) = "some information" lsvexample.items.add(item) end sub private sub lsvexample_selectedindexchanged(byval sender system.object, byval e system.eventargs) handles lsvexample.selectedindexchanged 'problem next line dim item mylistviewitem = ctype(lsvexample.selecteditems, mylistviewitem) 'tried too.. similar error dim item2 mylistviewitem = ctype(lsvexample.selecteditems(0), mylistviewitem) messagebox.show(item.id) messagebox.show(item.rootfolder) messagebox.show(item.name) messagebox.show(item.info(0)) end sub the error "value of type 'system.windows.forms.listview.selectedlistviewitemcollection' cannot converted 'myproject.mylistviewitem"
make class mylistboxitem inherit listviewitem.
Comments
Post a Comment