Windows Develop Bookmark and Share   
 index > Windows Forms General > Is there VB6 Collection object equivalent
 

Is there VB6 Collection object equivalent

Hi, I am newbie to Windows Form. I am VB6 developer. On client/server apps, I used collection object(s) to cache the data so all my other form can retrieve the data. The collection object is a seperate class than the VB form. I am learning the C# winForms and I donot know how to persist the data thru out entire application. Please give me some direction so I can research on. Thanks.
wpan  Thursday, June 28, 2007 8:21 PM
You really ought to take a look at the System.Collections.Generic namespace. It has several collection classes, Dictionary<> is probably the closest match to the VB6 Collection class if you use keys, List<> if you don't.

That said, the VB Collection class is still available. Project + Add Reference, choose "Microsoft.VisualBasic". Put "using Microsoft.VisualBasic" at the top of your source code. You'll however find out quickly that Collection is very awkward to use in C# due to the required type casts. Here's an example:

using Microsoft.VisualBasic;
...
private void test() {
Collection c = new Collection();
c.Add(0, "zero", null, null);
c.Add(1, "one", null, null);
c.Add(2, "two", null, null);
int value1 = (int)c["two"];
// NOTE: indexing starts from 1, not 0!
for (int ix = 1; ix <= c.Count; ++ix) {
int value2 = (int)c[ix];
}
foreach (int value in c)
Console.WriteLine(value);
}

nobugz  Tuesday, July 03, 2007 12:25 PM

Hi Whaien,

According to what you have described, I think the ADO.NET is what you want. ADO.NET is a data-access technology that enables applications to connect to data stores and manipulate data contained in them in various ways. It is based on the .NET Framework and it is highly integrated with the rest of the Framework class library. Below is some articles about ADO.NET

Code samples:

Hope this helps.

Regards

Rong-Chun Zhang  Tuesday, July 03, 2007 4:09 AM
You really ought to take a look at the System.Collections.Generic namespace. It has several collection classes, Dictionary<> is probably the closest match to the VB6 Collection class if you use keys, List<> if you don't.

That said, the VB Collection class is still available. Project + Add Reference, choose "Microsoft.VisualBasic". Put "using Microsoft.VisualBasic" at the top of your source code. You'll however find out quickly that Collection is very awkward to use in C# due to the required type casts. Here's an example:

using Microsoft.VisualBasic;
...
private void test() {
Collection c = new Collection();
c.Add(0, "zero", null, null);
c.Add(1, "one", null, null);
c.Add(2, "two", null, null);
int value1 = (int)c["two"];
// NOTE: indexing starts from 1, not 0!
for (int ix = 1; ix <= c.Count; ++ix) {
int value2 = (int)c[ix];
}
foreach (int value in c)
Console.WriteLine(value);
}

nobugz  Tuesday, July 03, 2007 12:25 PM

You can use google to search for other answers

Custom Search

More Threads

• drag and drop with visual c# 2005 express edition
• System.ComponentModel Magic Trick?
• ControlStyles.ContainerControl
• Widows-System error (a duplicate name...)
• Setting permissions from code
• Software to create UI for Winforms
• Proof of Concept: MDIForm does not call MdiChildActivate event
• Two forms in one Class
• new AutoSize mode in .net 2.0 Question
• checkbox eventhandler visual c# 2008