473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Two dimensional c# array list?

21
Hello guys,
I have a rather simple question.
I have two Arraylist's and I need to add them both at the same time into a DataGridView.
Here is the basic code I used:
Expand|Select|Wrap|Line Numbers
  1. protected ArrayList fPath = new ArrayList();
  2.         protected ArrayList md5File = new ArrayList();
  3. ...
  4.  
  5. foreach (string fp in fPath)
  6.                             {
  7.                         foreach (string md5 in md5File)
  8.                         {
  9.  
  10.                             int rw1 = dataGrid.Rows.Add();
  11.                             int rw2 = dataGrid.Rows.Add() - 1;
  12.  
  13.                             //Array file path
  14.                             dataGrid.Rows[rw1].Cells[0].Value = fp;
  15.  
  16.                             //Array md5
  17.                             dataGrid.Rows[rw2].Cells[1].Value = md5;
  18.                        }
  19.  
This is the only solution for inserting data to the datagridview in the same row...
And I think that this function is quite a ram eater.
So I deiced to make this better.
I wanted to create a two dimensional arraylist - so it could size up dynamically.

Expand|Select|Wrap|Line Numbers
  1. protected ArrayList[,] both = new ArrayList();
  2. both[0,x] = fpath values
  3. both[2,0] = md5File values;
  4.  
How can I do that/ or do you have any better suggestions.
Jan 19 '11 #1
2 35768
You can add an ArrayList as a single item in another ArrayList which makes the 2nd ArrayList a Multidimentional ArrayList

Expand|Select|Wrap|Line Numbers
  1. ArrayList both = new ArrayList();
  2.         for (int i = 0; i < fPath.Count; i++)
  3.         {
  4.             ArrayList temp = new ArrayList();
  5.             temp.Add(fPath[i]);
  6.             temp.Add(md5File[i]);
  7.             both.Add(temp);
  8.         }
  9.  
Jan 21 '11 #2
Curtis Rutland
3,256 Expert 2GB
Yes, I have better suggestions. First, don't use ArrayList. There's absolutely no need anymore. It was necessary in .NET 1.1, when there were no generics, but it's 2011 now. Use List<T>.

And second, if I understand you correctly, you really don't want multidimensional arrays, you want one array of elements that consist of two pieces of data tied together. Create a class.

Expand|Select|Wrap|Line Numbers
  1. public class MyData
  2. {
  3.   public string FilePath { get; set; }
  4.   public string MD5Hash { get; set; }
  5. }
  6. ...
  7. ...
  8. List<MyData> list = new List<MyData>();
  9. ...
Also, you should look into using the DataSource property of the DataGridView. You don't have to manually add each entry, you can just bind a list of content directly to the grid.
Jan 21 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: BCC | last post by:
Ive been googling and reading through my books but I haven't figured out a solution (much less an elegant one) to create a multidimensional array with a runtime determined number of dimensions. I...
1
by: seemanta dutta | last post by:
greetings C gurus, I would be grateful if I could know the answers to 2 questions: 1. I want to know how to pass a 2-dimensional array to a function, say foo() and what will be its prototype...
1
by: GB | last post by:
Hello, I have a recursion function which generate 1-dimensional vector of integers so for 3 cycles I have, for example, following vectors: int vec1 = {1,3,2,4}; int vec2 = {2,5,6,2}; int vec3 =...
6
by: fniles | last post by:
I need to store information in a 2 dimensional array. I understand ArrayList only works for a single dimensional array, is that correct ? So, I use the 2 dimensional array like in VB6. I pass the...
8
by: per9000 | last post by:
Hi all, I have a two-dimensional array of data, f.x int's. We can imagine that the array is "really large". Now I want the data in it and store this in a one-dimensional array. The obvious...
16
by: agent-s | last post by:
Basically I'm programming a board game and I have to use a list of lists to represent the board (a list of 8 lists with 8 elements each). I have to search the adjacent cells for existing pieces and...
10
by: SM | last post by:
Hello I'm trying to create a multi dimensional array in JavaScript, but after some reading i still can't figure out how to apply it to my model. Here it is: I have a list A and for each item...
3
by: OliveOyl3471 | last post by:
In Visual Basic.NET 2003, how do you populate a two dimensional array from a text file? I know how to check file existence, open the file for read, etc. I just can't get it to read more than one...
8
by: desktop | last post by:
I am simulating a display that consists of 20x20 pixels. All pixels are per default white but I would like to be able to turn on some or all the pixels. My idea was to create a 3 dimensional...
2
by: peachdot | last post by:
hi, Need to find the minimum element value in each row of list a.if the element of row is equal to the min value, i want to get its column index and put in another list b. example: a= a= a=...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.