Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Mon, 21 Jul 2008 05:13:22 -0700 (PDT),    group: microsoft.public.dotnet.framework        back       


store list passed by reference   
Hello All,

In a c# project I'm managing a List of objects of a custom class.

private List<MeshXNA> _Meshes = new List<MeshXNA>();

I then have a couple of different custom controls that display
information about the objects in that list (not only 3d).
I would like to achieve that the different controls could save the
reference to the list in order to be aware (at given intervals) of
further instances added.

at the moment I'm passing the data to the controls in this way:

bControl.SetModelList(ref _Meshes);

and the function is as follows:

public void SetModelList(ref
List<WinFormsGraphicsDevice.Device3D.MeshXNA> Meshes)
        {
            _meshes = Meshes;
            // some initialization code
        }

This seems to work, but I'm wondering if there's a better way of
sharing information structures across controls and form. Any
suggestion is welcome.

Best,
Claudio
date: Mon, 21 Jul 2008 05:13:22 -0700 (PDT)   author:   Bonghi

Re: store list passed by reference   
On Mon, 21 Jul 2008 05:13:22 -0700, Bonghi   
wrote:

> [...]
> This seems to work, but I'm wondering if there's a better way of
> sharing information structures across controls and form. Any
> suggestion is welcome.

Other than the apparently pointless use of the "ref" keyword, I don't see  
anything specifically wrong about the code you posted.  However, if you're  
interested in _doing_ something when the list instance is modified, you  
might prefer to use the BindingList class rather than List.  That class  
provides events to notify you of changes to the list.

It's not clear how in the code you posted you would be detecting changes  
to the list, but whatever you're doing, I think BindingList would probably  
work better, since it's designed for that purpose.

Pete
date: Mon, 21 Jul 2008 09:08:33 -0700   author:   Peter Duniho

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us