Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8736621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:20:47+00:00 2026-06-13T10:20:47+00:00

I am using C# and I am creating an ArrayList called importControlKeys which creates

  • 0

I am using C# and I am creating an ArrayList called “importControlKeys” which creates fine. However, I can’t for the life of my figure out a way to loop through the arrayList and pick out the values in the ArrayList for use in later code.

I know I’m missing something easy, but what is the syntax to extract a value from an ArrayList. I was hoping it was somethign like importControlKeys[ii].value in my code below, but that isn’t working.

I’ve searched on these boards and can’t find the exact solution, though I’m sure it’s easy. msot of the solutions say to re-write as a List but I have to believe there is a way to get data out of an array list without re-writing as a List

private void button1_Click(object sender, EventArgs e)
        {
            ArrayList importKeyList = new ArrayList();
            List<DataGridViewRow> rows_with_checked_column = new List<DataGridViewRow>();
            foreach (DataGridViewRow row in grd1.Rows) 
            { 
                if (Convert.ToBoolean(row.Cells[Del2.Name].Value) == true)
                { 
                    rows_with_checked_column.Add(row);
                    importKeyList.Add(row.Cells[colImportControlKey.Name].Value);

                    //string importKey = grd1.Rows[grd1.SelectedCells[0].RowIndex].Cells[0].Value.ToString();
                    //grd1.ClearSelection();
                    //if (DeleteImport(importKey))
                    //    LoadGrid();
                }                
            }
            for (int ii = 0; ii < rows_with_checked_column.Count; ii++)
            {
                //grd1.ClearSelection();
                string importKey = importKeyList[ii].value;  //ERRORS OUT

                if (DeleteImport(importKey))
                    LoadGrid();

                // Do what you want with the check rows  
            }

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:20:49+00:00Added an answer on June 13, 2026 at 10:20 am

    Not sure why you are using an ArrayList but if you need to loop thru it you could do something like this this

    if an element is not convertible to the type, you’ll get an InvalidCastException. In your case, you cannot cast boxed int to string causing an exception to be thrown.

    foreach (object obj in importKeyList ) 
    {
        string s = (string)obj;
        // loop body
    }
    

    or you do a for loop

    for (int intCounter = 0; intCounter < importKeyList.Count; intCounter++)
    {
        object obj = importKeyList[intCounter];
        // Something...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is actually faster? Simply creating a new ArrayList/ArrayCollection or re-using an existing one
I'm trying to group together radiobuttons that are creating using a for loop and
I am using vc++ and creating a thread using CreateThread function .Can I restart
I am creating and filling a text-boxes from an arraylist using struts iterator. Now
I am creating a simple reporting program using java and iReport (from jasper), which
The .NET 1.0 way of creating collection of integers (for example) was: ArrayList list
I'm creating an avi file out of bitmaps using C#. I'm able to create
I have a data structure, for which I am currently using an ArrayList .
I am extending ArrayList to create a custom ArrayList that can be modified using
I've an arraylist having 30000 items in it, what's the best way of creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.