c# - Combobox value (binded with an enum) in an instance -
good day lads!
i've got question.
i think i'll saving loads of text if see form, here go!
form:
private void form1_load(object sender, eventargs e) { /* held h1 = new held("tank", lanes.top); held h2 = new held("adc", lanes.bot); held h3 = new held("support", lanes.bot); listbox1.items.add(h1); listbox1.items.add(h2); listbox1.items.add(h3); */ //data koppelen cbrol.datasource = enum.getvalues(typeof(lanes)); } private void btnaanmaken_click(object sender, eventargs e) { int getal; if (checkemptyfields()) { messagebox.show("vul alle velden in!"); } else { if (checkmovementspeedisint(out getal)) { string naamhero = tbnaamhero.text; lanes lane = ??? int mspeedhero = getal; held nieuwheld = new held(naamhero, lane, getal); } } } private bool checkmovementspeedisint(out int getal) { return int32.tryparse(tbmovespeed.text, out getal); } private bool checkemptyfields() { return tbnaamhero.text == null || tbmovespeed.text == null || cbrol.selecteditem == null; }
held:
class held { private string naam; private lanes lane; int mspeed; public held(string anaam, lanes alane, int amspeed) { this.naam = anaam; this.lane = alane; this.mspeed = amspeed; } public override string tostring() { return this.naam + " " + this.lane.tostring(); } }
}
lanes:
enum lanes { top, mid, bot, jungle }
alright! can see have combined enum combobox. i'd put selected value (when user has pressed button "aanmaken/create") in instance.
how able convert object (from combobox) type (lanes)?
if haven't clarified enough, give me heads up!
ps: "???" in code place i'm not sure put since that's question hehe.
just use following:
lanes lane = (lanes)cbrol.selectedindex;
this works due enum
typeof int
, top
0
, , on...
Comments
Post a Comment