Solved

How to make multi-dimensional, untyped array?

Posted on 2008-06-24
1
564 Views
Last Modified: 2013-11-07
I would like to store a key with 4 associated controls to it so I can make changes to several controls within a loop. For example, this is what I'm trying to store into an array:

1.) header, (Literal)headerLiteral, (TextBox)headerTextbox, (DropDown)headerDropdown, (CheckBox)headerCheckbox;

2.) content, (Literal)contentLiteral, (TextBox)contentTextbox, (DropDown)contentDropdown, (CheckBox)contentCheckbox;

3.) footer, (Literal)footerLiteral, (TextBox)footerTextbox, (DropDown)footerDropdown, (CheckBox)footerCheckbox;

This way, I can do something like:
for (int i = 0; i < someArray.Count; i++)
{
    (Literal)someArray[i][1].Text = someArray[i][0] + " Section";
    (TextBox)someArray[i][2].Text = String.Empty;
    (DropDown)someArray[i][3].SelectedIndex = 0;
    (CheckBox)someArray[i][4].Checked = false;
}

Also, it might be too much to ask, but I also would like to reference the array element by the associative key name, like: (Literal)someArray["footer"][1].Text = "Footer Section";

Can anybody help me with choosing the right C# array/collection for this type of usage?
0
Comment
Question by:bemara57
1 Comment
 
LVL 7

Accepted Solution

by:
nsanga earned 500 total points
ID: 21856962
if the sub items in the array ( i.e. controls ) are predefined or known earlier you can do this...

1) define a class with the required types (header, Literal, TextBox,DropDown,CheckBox)
2) for each row create an object of above class type and set the members
3) add the above created objects to a hashtable or other collection dictionary typed collection with required keys....

It is always better to program things in systematic manner with required userdefined types.......

let me know if this is not you are looking for....
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now