Need help to solve "Index was outside the bounds of the array." error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kalaivani572
    New Member
    • Feb 2007
    • 5

    Need help to solve "Index was outside the bounds of the array." error

    i am getting "Index was outside the bounds of the array." error when i try to get the checked items from list view.
    the code is
    [code=c#]
    private void btnFinish_Click (object sender, EventArgs e)
    {
    WaitCallback async = new WaitCallback(Ex ecutefeed);
    ThreadPool.Queu eUserWorkItem(a sync, alParams);
    waitBar.ShowDia log();
    }

    private void ExecuiteDataFee d(object param)
    {
    ArrayList alParams = (ArrayList)para m;

    if(this.lstInvo iceTran.Checked Items.Count > 0)
    {
    this.m_InvoiceS election = null;
    for ( int y = 0; y < lstInvoiceTran. CheckedItems.Co unt; y++ )
    {
    this.m_InvoiceS election += this.lstInvoice Tran.CheckedIte ms[y].SubItems[0].Text;
    this.m_InvoiceS election += ", ";
    }

    m_InvoiceSelect ion = m_InvoiceSelect ion.Remove(m_In voiceSelection. Length - 2, 2);
    m_InvoiceSelect ion = m_InvoiceSelect ion.Replace(" ","");
    }
    }
    [/code]
    when i debug, " lstInvoiceTran. CheckedItems.Co unt" in the FOR loop is failing.
    please help.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    What's this.m_InvoiceS election = null; for?

    P.S That part can't be responsible for the execption. The exception is thrown in one of your array index accesses.

    Comment

    • kalaivani572
      New Member
      • Feb 2007
      • 5

      #3
      Originally posted by r035198x
      What's this.m_InvoiceS election = null; for?

      P.S That part can't be responsible for the execption. The exception is thrown in one of your array index accesses.
      thats rite.
      In debug mode, when the cursor in the button click event, through command window, if i access"lstInvoi ceTran.CheckedI tems.Count", then it is giving the exact count.
      But if i do the same inside "ExecuteFee d" function, in command window "Cannot Obtain Value" error appears and then the above exception is thrown in application.
      can u please clarify whether the "Listview" property cant be used inside a function?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        I am thinking it is angry because you are doing this in a "threaded" context.
        You might have to look for synclocks or just plain mutexs to keep it from being angry about your non-threadsafe access?

        Comment

        Working...