c# 2.0 - How to use an object across winforms -
so have list of custom object class code looks follow
var itemlist = new list<item>();
so item simple class inherits defaults, , has 3 private fields called
private double price; private string @url; private string name; public double setprice(string price) { this.price = price; }
my question since 1 answered on how remove lists how can access created item object list , edit fields separate windows form. i.e.
list<item> items = new list<item>(); private void itemlistbox_doubleclick(object sender, eventargs e) { if (itemlistbox.selecteditem != null) { var editor = new form2(); editor.show(); //creating new winform } }
how can edit item variable in edit form. if went second form. how access name property item in collection?
if have reference item
, can use remove
:
itemlist.remove(someitem);
or remove item
@ particular index, use removeat
:
itemlist.removeat(5);
now, access itemlist
across different classes, make pulic static field or property:
public class myform { public static list<item> itemlist; }
and reference using name of class defined:
myform.itemlist.add(...);
Comments
Post a Comment