473,503 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2808
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
6384
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
2599
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
2682
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
2243
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
2415
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
16852
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
23623
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
6409
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
1474
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
4552
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
7202
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
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
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...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7458
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.