473,386 Members | 1,720 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,386 software developers and data experts.

Array question

I have a Jagged array that stores RoutingIDs and theirs corresponding Bank
Names.
I can access it as myArray[row][column]. The column index indicates whether
the value is RoutingID or a BankName.

myArray[0][0] - first bank's RoutingID
myArray[0][1] - first bank's Name
myArray[1][0] - second bank's RoutingID
myArray[1][1] - second bank's Name
....

Now I want to perform few operations on this array. But don't know what is
the best way.

1) I would like to display all Routing IDs in a combobox.
2) I would like to display all distinct Bank Names in another combobox.
NOTE: I need to display distinct Names. The array may contain same Bank Name
more than once with different Routing IDs.
3) When they select an item in either of the two comboboxes, I would select
their corresponding value in the second combobox.

Thanks.

Nov 16 '05 #1
2 2789
I would have to suggest switching from that jagged array to a DataTable.
First off, the DataTable can act as a small database, allowing sorting and
simple queries against it and will make it a lot easier to do things like
this. The trade off *might* be a bit more memory used for the DataTable and
also a bit more code to load it. But it should be easy to use the same code
that you are using to load your array.

Using the jagged array: (Note, I use ArrayLists for temp storage. I find
that they perform better than calling Array.Copy after every insert.)

To get all the Routing IDs:

<pseudo-code>
ArrayList tempArray = new ArrayList();
for(int r = 0; r < myArray.Length; r++)
{
tempArray.Add(myArray[r][0]);
}
return (string[])tempArray.ToArray(typeof(string));
</pseudo-code>

For getting all distinct bank names just do the same thing

<pseudo-code>
ArrayList tempArray = new ArrayList();
for(int r = 0; r < myArray.Length; r++)
{
if(!tempArray.Contains(myArray[r][1]))
{
tempArray.Add(myArray[r][0]);
}
}
return (string[])tempArray.ToArray(typeof(string));
</pseudo-code>

For the third one, I think the FindString or FindStringExact method of the
DropDownList will get you what you need. You could also use the
SelectedIndex property if you are bound your array.

--
HTH

Kyril Magnos

Question of the day:
What is Mono?
A) Disease where the lymph nodes become swollen.
B) A single sound
C) A synonym for one
D) A port of .NET meant to royally irritate MSFT
E) All of the above.

"Nikhil Patel" <ni********@aol.com> wrote in message
news:eE**************@TK2MSFTNGP09.phx.gbl...
|I have a Jagged array that stores RoutingIDs and theirs corresponding Bank
| Names.
| I can access it as myArray[row][column]. The column index indicates
whether
| the value is RoutingID or a BankName.
|
| myArray[0][0] - first bank's RoutingID
| myArray[0][1] - first bank's Name
| myArray[1][0] - second bank's RoutingID
| myArray[1][1] - second bank's Name
| ...
|
| Now I want to perform few operations on this array. But don't know what is
| the best way.
|
| 1) I would like to display all Routing IDs in a combobox.
| 2) I would like to display all distinct Bank Names in another combobox.
| NOTE: I need to display distinct Names. The array may contain same Bank
Name
| more than once with different Routing IDs.
| 3) When they select an item in either of the two comboboxes, I would
select
| their corresponding value in the second combobox.
|
| Thanks.
|
|
|
Nov 16 '05 #2
Hi
1) I would like to display all Routing IDs in a combobox.
For that you should loop on the first index(lets say you will use a
variable int i for the loop)( and on that loop you add MyArray[i][0] to the
items collection of your combobox .
One more simple way to bind the combobox to the array and select the index
routingID as the display member

2) I would like to display all distinct Bank Names in another combobox.
This best done in a loop this time add MyArray[i][1] to the combobox
items collection , and you need to check for duplicate before adding the
item.
3) When they select an item in either of the two comboboxes, I
would select
their corresponding value in the second combobox.
You write a handler for selection changed event in both
combobox, for the first , you search for a match looping on MyArray[i][0]
and display the correspondence value at [i][1] , and the opposite would be
done in the other combo handler
hope that helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: SilverWolf | last post by:
I need some help with sorting and shuffling array of strings. I can't seem to get qsort working, and I don't even know how to start to shuffle the array. Here is what I have for now: #include...
9
by: buda | last post by:
Hi, I've been wondering for a while now (and always forgot to ask :) what is the exact quote from the Standard that forbids the use of (&array) (when x >= number_of_columns) as stated in the FAQ...
3
by: Pol Bawin | last post by:
Hi All, One : I have a property that get/set a array of an abstract class A By default my array is null In the propertygrid, It is not works correctly when my array is null. (when my array...
11
by: Geoff Cox | last post by:
Hello, I am trying to get a grip on where to place the initialization of two arrays in the code below which was created using Visual C++ 2005 Express Beta 2... private: static array<String^>^...
28
by: anonymous | last post by:
I have couple of questions related to array addresses. As they belong to the same block, I am putting them here in one single post. I hope nobody minds: char array; int address; Questions...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
51
by: Pedro Graca | last post by:
I run into a strange warning (for me) today (I was trying to improve the score of the UVA #10018 Programming Challenge). $ gcc -W -Wall -std=c89 -pedantic -O2 10018-clc.c -o 10018-clc...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
8
by: T. Wintershoven | last post by:
Hello all, I have a form with some checkboxes. The names of these checkboxes come from an array. When i click the submit button the resultcode doesn't recognize the names when i want to check...
4
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.