473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Binding an ArrayList to a Form

Hi all,

I have the following simple class which I use to store a set of lab
objects:

/// <summary>
/// Represents a Collection of Labs
/// </summary>
public class CLabCollection
{
// stores a set of labs
public ArrayList labCollection = new ArrayList();

/// <summary>
/// Get/Set the collection of Labs
/// </summary>
public Lab[] LabCollection
{
get
{
Lab[] tempLabCollection = new
Lab[labCollection.Count];
labCollection.CopyTo(tempLabCollection);
return tempLabCollection;
}
set
{
if (value == null) return;
Lab[] tempCLabCollection = (Lab[])value;
labCollection.Clear();
foreach (Lab lab in tempCLabCollection)
labCollection.Add(lab);
}
}

/// <summary>
/// Returns the collection of labs as an ArrayList. Since
ArrayList is inherited from IList,
/// it can be bound to a control
/// </summary>
public ArrayList LabArrayList
{
get
{
return labCollection;
}
}

/// <summary>
/// Constructor
/// </summary>
public CLabCollection(){}

/// <summary>
/// Add a Lab to the Collection.
/// </summary>
/// <param name="lab"></param>
public void Add(Lab lab)
{
labCollection.Add(lab);
}

/// <summary>
/// Get the first Lab in the Collection. Exception thrown if
none exists
/// </summary>
public Lab FirstLab
{
get
{
if (labCollection.Count == 0)
throw new ApplicationException("Can't get first
Lab in Lab Collection since it is empty.");

return (Lab)labCollection[0];
}
}
}

It then become easy to serialise to objects of CLabCollection as
follows:

class CFramework
{
CLabCollection labCollection = new CLabCollection();
public ArrayList LabArrayList
{
get
{
return labCollection.LabArrayList;
}
}

public CFramework()
{
XmlSerializer xmlSerializer = new
XmlSerializer(typeof(CLabCollection));

using (StreamReader streamReader = new
StreamReader(xmlLabDirectoriesPath))
{
labCollection =
(CLabCollection)xmlSerializer.Deserialize(streamRe ader);
}
}
}

Then in my MainForm I can do something like this:

CurrencyManager currencyManagerLab =
(CurrencyManager)this.BindingContext[Environment.Framework.LabArrayList,
null];

In your opinion is this a good approach, and if not, why not? I'm
expossing the same array (CLabCollection:labCollection) via two
seperate accessors (LabCollection and LabArrayList), but this feels
correct to me since I'm using it the array for two different purposes.

Thanks,

Aine

Oct 25 '07 #1
0 970

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

Similar topics

0
by: berg | last post by:
All, I am binding an ArrayList full of custom objects to an DataGrid. The property in the custom class are all public. I define a DataGridTableStyle and set the MappingName to "ArrayList". I...
3
by: Jim Bancroft | last post by:
Hi everyone, I'm binding an ArrayList to a DataGrid for the first time (I'm used to binding DataSets and DataTables) and I was wondering if I could somehow "name" the ArrayList, so that I can...
4
by: Alan Silver | last post by:
Hello, I'm trying to use an ArrayList to do data binding, but am getting an error I don't understand. I posted this in another thread, but that was all confused with various other problems,...
16
by: Michael C# | last post by:
I'm binding a Combobox to an Arraylist, and I'd like to set the ValueMember and DisplayMember properties of the Combobox. Is this possible, or do I need to bind to a DataTable? Thanks
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
1
by: Dean Slindee | last post by:
Can someone explain how to remedy the two late binding errors below when Option Strict On: Public Function ControlDataRowArrayListPaint(ByRef frm As Form, _ ByRef ctl As Control, _ ByRef...
2
by: Dean Slindee | last post by:
Can someone explain how to remedy the two late binding errors below when Option Strict On: Public Function ControlDataRowArrayListPaint(ByRef frm As Form, _ ByRef ctl As Control, _ ByRef dr...
9
by: Miro | last post by:
VB 2003 and Im still new to vb, so i hope i can explain this as best I can. I have a variable defined as such: ( simple example ) Dim AVariableOfSorts(,) As Object = _ { _ {"Last", "String",...
3
by: kevinwolfe | last post by:
Hi all. I'd like any suggestions on how I can get my data set (not a DataSet) bound to a couple of controls on a form. Let me start by describing what my data looks like. Each entry correlates...
3
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.