Solved

Any way to achieve Sticky reference?

Posted on 2004-09-25
6
210 Views
Last Modified: 2010-04-15
Here is an example to hopefully help clarify what I'm trying to do.  

I load a collection with objects (TestClass).  I then bind this collection to a datagrid.  I then also bind text a text box to the current row in the gird like this:
grdList.DataSource = myCollection;
_refClass = (TestClass)myCollection[grdList.CurrentRowIndex];                  

txtRefName.DataBindings.Add("Text",_refClass, "Name");

The obviously the variable _refClass is just acting as a pointer which holds a reference to the item in the collection and then that reference is bound to the textbox.  So if in the future _refClass is set to another item in the collection the TextBox will not reflect that change unless it is rebound.

However, what I'd like to know is, is there a way actually bind the textbox to _refClass so that any time _refClass is pointed to a new item in the collection the TextBox will reflect this without having to be rebound.

The scenerio above isn't a real project I'm working on, I just thought it was the easist way to explain what I am looking for.  I have also coded this into a simple project as an example.  If it will help anyone to understand the issue I can email the project to them.

Thanks so much for your time!
0
Comment
Question by:carpediem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 10

Expert Comment

by:ptmcomp
ID: 12151123
Try:
txtRefName.DataBindings.Add(new Binding("Text", myCollection, ""));
PS: It's not tested but I'm sure you have to bind to the collection. The CurrencyManager on the form will handle the row changing thing.
0
 
LVL 1

Author Comment

by:carpediem
ID: 12151159
Sorry, my example wasn't very clear (or was maybe to clear and thus hid my real question).

In more generic terms:
Say there is an object X in memory and then object Y just holds a reference to object X.

I then set object Z = object Y.  So now object Z just points to object X.  

What I would like to know is there any way in C# to handle a case where I now point object Y to object Q and I would like object Z to automatically point to object Q as well.

So instead of having object Z directly point to object X when I set object Z = object Y, object Z actually points to object Y so if I point object Y elsewhere object Z will automatically then point to that other object I've updated object Y to point to.

0
 
LVL 10

Accepted Solution

by:
ptmcomp earned 500 total points
ID: 12152333
This is done by the CurrencyManager which is stored in the BindingContext on the Form.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# MVC Insert Multiple Row into DB 2 95
asp web application 3 55
C# Linq Select From List 3 132
Header Font Size in Grid View 6 49
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses

732 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