Displaying Contents of ArrayList

B

Beza

I have an ArrayList which stores x number of "Policy" objects, where x is
the number of rows returned from a earlier SQL query (therefore it is
changeable).

Each "Policy" has a few methods within it that returns values.

How do I display a row of information for each "Policy" (stored in the
ArrayList) in the browser?

Also, what is the best way of assigning values returned from object methods
to specfic fields in DataLists, DataGrids etc?
 
C

craig

I have never actually done this before, but from what I understand, you can
add databindings to the datagrid databindings collection. Each databinding
binds the value of a property in your Policy objects to a column in the
datagrid.

In order to do this, your collection must implement the IList interface,
which the ArrayList does.
 
C

Chris Hornberger

Regarding the array list, try: (and this will be long-hand, there are
plenty of places to take short cuts, but I'm doing it long hand to
show you the steps)

object[] policies = ArrayListofPolicies.ToArray();
// hashed out - this might be ordered, not sure.
foreach( object o in policies ){
Policy p = (Policy)o;
string txt = p.Method1() + "\t";
txt += p.Method2();
txt += p.Method3();
txt += p.Method4();
Console.WriteLine( txt );
}

//or indexed in order:
for( int x=0; x<policies.Length; x++ ){
Policy p = (Policy)policies[x];
string txt = p.Method1();
// .......
Console.WriteLine( txt );
}

Again, this is sloppy long-hand, but I think you get the gist of it.

Also, if you wrote the Policy object and can change it, you might want
to expose the "pieces of information" as an array of values.

for( int x=0; x<policies.Length; x++ ){
Policy p = (Policy)policies[x];
string txt = "";
for( int y=0; y<p.Values.Length; y++ ){
txt += p.Values[x] + "\t";
}
Console.WriteLine( txt );
}

or with a class indexer:
for( int x=0; x<policies.Length; x++ ){
Policy p = (Policy)policies[x];
string txt = "";
for( int y=0; y<p.ValueCount; y++ ){
txt += p[x] + "\t";
}
Console.WriteLine( txt );
}

There are many options.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top