Wrox Programmer Forums
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 12th, 2008, 10:44 AM
Authorized User
 
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default ArrayList

I've read, in several different websites, that one can put any object into an ArrayList. Does this include an ArrayList? Is it possible to have an ArrayList of ArrayLists? I've not tried yet to build my solution with it set up this way. I would like to find out from any of you 'experts' first, before I go through a lot of trouble attempting to make it work if it is not supposed to work.

RLELLE
__________________
RLELLE
 
Old February 12th, 2008, 10:54 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Yes you can do that something like this will work:

        ArrayList ar = new ArrayList();
        ArrayList ar2 = new ArrayList();
        ar2.Add("foo");
        ar.Add(ar2);

        ArrayList ar3 = (ArrayList)ar[0];
        Response.Write(Convert.ToString(ar3[0]));

foo is wrote to the screen. You could also use a List<T> for this secnario.

hth.


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old February 12th, 2008, 11:20 AM
Authorized User
 
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your prompt reply.

Below is what I am attempting. Does it make sense?

public ArrayList alRvwrNm = new ArrayList();
public ArrayList alActCnt = new ArrayList();
public ArrayList alPrfrNm = new ArrayList();
public ArrayList alDdoCd = new ArrayList();
public ArrayList alGridview = new ArrayList();

alGridview.Add(alPrfrNm, alDdoCd, alActCnt, alRvwrNm);

I am collecting data from three different tables. The data I am collecting is to be be sorted, then posted to a gridview. I had it all on a gridview already, but the column that I needed to sort was a template field. I soon discovered that a template field could not be sorted. So, I had to resort to building and combining these arrays, sorting the data, then posting it to the gridview.

RLELLE
 
Old February 12th, 2008, 11:35 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Add() only takes one argument. The above code will throw an error telling you as much.

I am curious, why are you using an ArrayList as opposed to an ObjectDataSource or SQL Datasource? This seems like alot of work for something so trivial.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old February 12th, 2008, 03:38 PM
Authorized User
 
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am converting an application written in java over to C#. The programmer that wrote the app in java says he gathered all this data into arrays, sorted the data, then presented it on a form. I am trying to mimic that, but honestly, I do wonder if I could gather up all this data into a dataset, do the sorting, then bind to a gridview. The problem is that the data gathering is a two or three step process. So, storing the data into arrays seemed reasonable. Like I said earlier, I had all this working just fine with a gridview except for the fact that it was not sorted. The column to be sorted was a template field, and the gridview did not like me sorting on that.

RLELLE
 
Old February 12th, 2008, 04:05 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

That doesn't seem to make sense. I declare my SortExpressions in the TemplateField and do not have a problem with this? Are you sure you have set up your sorting correctly? Check out Scott Gu's page, it may shed some light on your problem:

http://weblogs.asp.net/scottgu/archi...11/437995.aspx


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
ArrayList sort collie C# 1 August 28th, 2007 08:08 AM
ArrayList with UserControl rhd110 General .NET 2 August 12th, 2007 12:29 PM
ArrayList Problem erictamlam C# 2005 3 May 12th, 2007 10:04 AM
Help with an arraylist crazy-nun General .NET 4 July 14th, 2005 03:32 AM
ArrayList kobystud C# 4 May 25th, 2004 02:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.