hello everyone, i'm wroking with a List<string> and i want to copy it's values into a variable string each but i keep getting an index error. i declared a class library which looks like this:
public class SalesData
{
public List<string> GetSales( string Clientname, string Empname, string Breadtype)
{
List<string> getSales=new List<string>();
string cname, ename, btype;
cname = Clientname;
ename = Empname;
btype = Breadtype;
getSales.Add(cname);
getSales.Add(ename);
getSales.Add(btype);
return getSales;
}
}
and i got the values from this code
public void PreviewMeth()
{
//copy values from main page to Preview Page
Client_Name_Main = ClientList_Lbox.SelectedItem.ToString();
Bread_Type_Main = BreadType_Dd.SelectedItem.ToString();
//Bread_Quantity = BreadQty_UpDown
Deliverer_Main = Deliv_Dd.SelectedItem.ToString();
//fill in the sales class
gemData= fillemData.GetSales(Client_Name_Main, Deliverer_Main, Bread_Type_Main);
//call up preview page
Submit_Btn.Enabled = true;
Preview_Page PrevPage = new Preview_Page();
PrevPage.ShowDialog();
}
and this bit of code is meant to get the values from the string and input them in the variables, but it gives me an index error.
private void Preview_Page_Load(object sender, EventArgs e)
{
myDate = newTime.Date.ToString();
myDate_Lb.Text = myDate;
//load client details
prevData = getFormData.DisplayData();
for (int i = 1; i <= 3; i++)
{
switch (i)
{
case 1: C_name = prevData[i].ToString(); break;
case 2: D_name = prevData[i].ToString(); break;
case 3: B_type = prevData[i].ToString(); break;
}
}
//put names up on labels
Db_ClientName_Lb.Text = C_name;
}
is there anything i'm doing wrong here guys?