Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Any way to achieve Sticky reference?

Posted on 2004-09-25
6
Medium Priority
?
215 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 2000 total points
ID: 12152333
This is done by the CurrencyManager which is stored in the BindingContext on the Form.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

609 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