I'm passing in various variables into my method to be stored into a collection. I am storing string, ints and bools which I can (now) do quite easily, however, I now need to pass in some parameters. These are taken from a listbox that has been populated by the user.
This is my SAVE code:
private void btnSaveCont_Click(object sender, RoutedEventArgs e)
{
if (tbName.Text == "")
{
MessageBox.Show("Please enter a continent name and ensure all fields are entered and territories are assigned", "Error");
}
else
{
string cname = tbName.Text;
int cbonus = int.Parse(tbBonus.Text);
//I'M GUESSING I NEED A FOREACH LOOP HERE TO GET THE ITEMS IN THE LIST AND STORE THEM?
if (cbOverride.IsChecked == true)
{
if (cbPartially.IsChecked == true)
{
gbl_clijst.clijst.Add(new cdata(cname, cbonus, true, true, //THIS IS WHERE I NEED TO PASS IN THE STRINGS));
}
else
{
gbl_clijst.clijst.Add(new cdata(cname, cbonus, true, false));
}
}
else
{
gbl_clijst.clijst.Add(new cdata(cname, cbonus, false, false));
}
}
}
So, let's assume the user has two entries in the listbox (e.g. Lightning and Thunder), how would I pass these through into my method?
This is my class and method they are being passed into:
class cdata
{
public string cname;
int bonus;
bool cbP, cbO;
public cdata(string cname, int bonus, bool cbP, bool cbO, params string[] AssignedTList)
{
this.cname = cname;
this.bonus = bonus;
this.cbP = cbP;
this.cbO = cbO;
Debug.WriteLine("This collection contains " + cname + ", " + bonus + ", " + cbP + ", " + cbO + ", " + AssignedTList);
}
}
static class gbl_clijst
{
static gbl_clijst()
{
Debug.WriteLine("** creating application scope instance");
clijst = new List<cdata>();
}
static public List<cdata> clijst;
}
Mind you, I could be well off here and there is a simpler way to do this...lol
Premier2k

New Topic/Question
Reply



MultiQuote





|