473,830 Members | 2,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multidimensiona l Generics

I have a list:

List<RichTextBo xrtb;

That represents an NxM matrix of rtb's. Is there some way to initialize a
generic that will allow me to access the List like a multidimensiona l array
i.e.;

rtb[2, 3].Text = "some text";


Sep 2 '06 #1
8 2893
Hi,

you can do it like this:

List<List<RichT extBox>rtb = new List<List<RichT extBox>>();

rtb[2][3].Text = "some text";

Regards,

Wiebe Tijsma

Chuck Bowling wrote:
I have a list:

List<RichTextBo xrtb;

That represents an NxM matrix of rtb's. Is there some way to initialize a
generic that will allow me to access the List like a multidimensiona l array
i.e.;

rtb[2, 3].Text = "some text";

Sep 2 '06 #2
"Wiebe Tijsma" <wi*********@CA PITALStijsma.co ma écrit dans le message de
news: OC************* *@TK2MSFTNGP04. phx.gbl...

| List<List<RichT extBox>rtb = new List<List<RichT extBox>>();

.... not forgetting :

rtb[2][3] = new RichTextBox(); or similar :-)

| rtb[2][3].Text = "some text";

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Sep 2 '06 #3
Yes, thanks for the addition, lets not forget adding the lists itself as
well :)

List<List<RichT extBox>rtb = new List<List<RichT extBox>>();
rtb.Add(new List<RichTextBo x>());
rtb[0].Add(new RichTextBox());
rtb[0][0].Text = "some text";

Wiebe

Joanna Carter [TeamB] wrote:
"Wiebe Tijsma" <wi*********@CA PITALStijsma.co ma écrit dans le message de
news: OC************* *@TK2MSFTNGP04. phx.gbl...

| List<List<RichT extBox>rtb = new List<List<RichT extBox>>();

... not forgetting :

rtb[2][3] = new RichTextBox(); or similar :-)

| rtb[2][3].Text = "some text";

Joanna
Sep 2 '06 #4
Q: why not just use a multi-dimensional array of rtbs? However, the
following would wrap it reasonably well, assuming they exist first. At
least, it doesn't appear "jagged".

Marc

public class ArrayWrapper<T{
private readonly IList<Tdata;
private readonly int width;
public ArrayWrapper(IL ist<Tdata, int width) {
this.data = data;
this.width = width;
}
public T this[int x, int y] {
get { return data[GetIndex(x, y)]; }
set { data[GetIndex(x,y)] = value; }
}
private int GetIndex(int x, int y) {
return (y * width) + x;
}
}

Sep 2 '06 #5
Great! Thanks Wiebe, Joanna and Marc. :)
"Wiebe Tijsma" <wi*********@CA PITALStijsma.co mwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Yes, thanks for the addition, lets not forget adding the lists itself as
well :)

List<List<RichT extBox>rtb = new List<List<RichT extBox>>();
rtb.Add(new List<RichTextBo x>());
rtb[0].Add(new RichTextBox());
rtb[0][0].Text = "some text";

Wiebe

Joanna Carter [TeamB] wrote:
>"Wiebe Tijsma" <wi*********@CA PITALStijsma.co ma écrit dans le message
de news: OC************* *@TK2MSFTNGP04. phx.gbl...

| List<List<RichT extBox>rtb = new List<List<RichT extBox>>();

... not forgetting :

rtb[2][3] = new RichTextBox(); or similar :-)

| rtb[2][3].Text = "some text";

Joanna

Sep 3 '06 #6
Wiebe I'm a little confused on this. Should the code look more like this:

List<List<RichT extBox>rtb = new List<List<RichT extBox>>();
rtb[0].Add(new List<RichTextBo x>());
rtb[0][0].Add(new RichTextBox());
rtb[0][0].Text = "some text";
"Wiebe Tijsma" <wi*********@CA PITALStijsma.co mwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Yes, thanks for the addition, lets not forget adding the lists itself as
well :)

List<List<RichT extBox>rtb = new List<List<RichT extBox>>();
rtb.Add(new List<RichTextBo x>());
rtb[0].Add(new RichTextBox());
rtb[0][0].Text = "some text";

Wiebe

Joanna Carter [TeamB] wrote:
>"Wiebe Tijsma" <wi*********@CA PITALStijsma.co ma écrit dans le message
de news: OC************* *@TK2MSFTNGP04. phx.gbl...

| List<List<RichT extBox>rtb = new List<List<RichT extBox>>();

... not forgetting :

rtb[2][3] = new RichTextBox(); or similar :-)

| rtb[2][3].Text = "some text";

Joanna

Sep 3 '06 #7
"Chuck Bowling" <ch**********@s bcglobal-NO-SPAM.neta écrit dans le message
de news: e3************* *@TK2MSFTNGP04. phx.gbl...

| Wiebe I'm a little confused on this. Should the code look more like this:
|
| List<List<RichT extBox>rtb = new List<List<RichT extBox>>();
| rtb[0].Add(new List<RichTextBo x>());
| rtb[0][0].Add(new RichTextBox());
| rtb[0][0].Text = "some text";

Chuck, thanks for filling in the holes, this is perfectly correct, but was
assumed by some of us :-)

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Sep 3 '06 #8
whoops... seems u worked it out perfectly

Joanna Carter [TeamB] wrote:
"Chuck Bowling" <ch**********@s bcglobal-NO-SPAM.neta écrit dans le message
de news: e3************* *@TK2MSFTNGP04. phx.gbl...

| Wiebe I'm a little confused on this. Should the code look more like this:
|
| List<List<RichT extBox>rtb = new List<List<RichT extBox>>();
| rtb[0].Add(new List<RichTextBo x>());
| rtb[0][0].Add(new RichTextBox());
| rtb[0][0].Text = "some text";

Chuck, thanks for filling in the holes, this is perfectly correct, but was
assumed by some of us :-)

Joanna
Sep 3 '06 #9

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

Similar topics

3
1794
by: Naomi | last post by:
Hi there, Just wondering, if there is any way to have a dynamic / unspecified size of an array? It obviously needs to be updated, deleted etc. The only way I thought is by making the array massive at the start? Any other ideas? Apparently Hashtable, ArrayList etc are useless as they all take one dimension. :( Please help me! Thanks, Naomi
3
8201
by: Claire | last post by:
I have a multidimensional array defined as private double myArray = new double; The first column of the array contains X values, the other contains Y values I have a charting function defined as Add(Array XValues, Array YValues) How do I call the Add function, passing my array columns please. thanks
2
1381
by: Henrik | last post by:
im reciving an error when i tries to read multidimensional XML data, into my system. I'm receving the same errors discriped at: http://support.microsoft.com/default.aspx?scid=kb;en-us;325695 And http://support.microsoft.com/kb/325696/EN-US/ But I can't find a solution for the problem???
23
2562
by: Luc Vaillant | last post by:
I need to initialise a typed parameter depending of its type in a generic class. I have tried to use the C++ template form as follow, but it doesn't work. It seems to be a limitation of generics vs C++ templates. Does anyone knows a workaround to do this ? Thx : public class C<T> { private T myValue;
12
2749
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as it defines the language more completely. Great to use.
9
5988
by: sloan | last post by:
I'm not the sharpest knife in the drawer, but not a dummy either. I'm looking for a good book which goes over Generics in great detail. and to have as a reference book on my shelf. Personal Experience Only, Please. ...
2
3653
by: BB | last post by:
Hello, I have a HTML form containing multidimensional selects listing equipments and their quantitites. This allow the users to select the kind of equipment and quantitites they would like to book. Upon onChange select event I would like to parse the data into a multidimensional Javascript array in order to check equipment availability for booking. But I can't figure out how to parse and upon JS HTML DOM reference I am not even sure...
13
3842
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an application that needs implementations in both Java and C#. I have the Java side done, and it works fantastic, and the C# side is nearly there. The problem I'm running into has to do with the differences in implementations of Generics between the two...
9
4504
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize function: x = new int;
0
9781
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10769
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10477
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10197
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6944
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5777
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4408
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 we have to send another system
2
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3072
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.