jeudi 13 août 2015

Index was outside the bounds of the array . But All arrays are correct

Hello i'm getting "Index was outside the bounds of the array" if i'm putting value (i) in itemsWS.getItemInfo(itemLis[i].ToString())

object[] itemDetails;
object[] itemLis = itemsWS.searchItem("", "bread", "all");
int xs = 35;
int clefts = 0;

for (int i = 0; i < itemLis.Length; i++)

{
    itemDetails = itemsWS.getItemInfo(itemLis[i].ToString());
    Button myButtons = new Button();
    myButtons.Click += delegate
    {

        dataGridView1.ColumnCount = 11;

        dataGridView1.Columns[0].Name = "Item Code";
        dataGridView1.Columns[1].Name = "Description";
        dataGridView1.Columns[2].Name = "Sale Price";
        dataGridView1.Columns[3].Name = "Category";
        dataGridView1.Columns[4].Name = "Type";
        dataGridView1.Columns[5].Name = "Status";
        dataGridView1.Columns[6].Name = "Low Count";
        dataGridView1.Columns[7].Name = "Medium Count";
        dataGridView1.Columns[8].Name = "High Count";
        dataGridView1.Columns[9].Name = "Item Picture";
        dataGridView1.Columns[10].Name = "TEST";

        //here is where i'm getting error if i put i on the []

        itemDetails = itemsWS.getItemInfo(itemLis[i].ToString());

        //

        dataGridView1.Rows.Add(itemDetails);
        MessageBox.Show("data grid displayed!");

    };


    myButtons.Text = itemDetails[1].ToString() + "\n  " + itemDetails[2].ToString();
    myButtons.Top = cleft * 180;
    myButtons.Left = 70;
    myButtons.Location = new Point(xs, clefts);
    myButtons.Size = new Size(100, 60);
    tabPage1.Controls.Add(myButtons);
    xs += 135;

    if (xs >= 537)
    {
        xs = 35;
        clefts += 80;
    }

(this is the database)

enter image description here

The problem is if I replace [i] with [0]. It will only display the first value item in the database

(here is the GUI if i replaced [i] with [0]) Any button clicked would repeat the same output

enter image description here

Please any help would be greatly appreciated. I'm trying to display items from MySQL using new buttons which was generated that would be displayed on the datagridview. Thanks

Note : that itemsWS is a web service coming from

private KPWSItems itemsWS = new KPWSItems();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire