Solved

how a user control updates its properties

Posted on 2013-01-14
3
256 Views
Last Modified: 2013-01-15
hi - i'm using vs2010 and .net 4.0
I've been chasing this for several hours and i now understand what it is happening, but not why. I have a user control that sits on a form. I update a property using a standard assign. the variable that is used on the form then is zeroed about 10 lines further down. Instead of behaving like i expected - where the property holds the value it was set with, it passes the new value to the property without an explicit assign statement and the user control now uses the new (and not desired) value to perform its next operation. the form code is below. the relevant variable is "captured index".
if i understood why this is happening, i could design this better.
if (npv != null)
                        {
                            npv.CurrentCoordinates[0] = (double)tempX;
                            npv.CurrentCoordinates[1] = (double)tempY;
                            npv.CapturedIndex = capturedIndex;

                           
                            Application.DoEvents();
                        }

                        ChanTable.Rows[capturedIndex[0]]["channelData"] = temp;
                        ChanTable.Rows[capturedIndex[0]]["chanDataDirty"] = true;
                        downloadChan_DGV.Rows[capturedIndex[0]].Cells        ["indicator_col"].Style.BackColor = Color.Orange;
                        isDirty = true;

                        // reset state variables
                        shiftInsertionDone = false;
                        mouseCapture = false;
                        capturedIndex[0] = 0;
                        capturedIndex[1] = 0;
if i put both the control and form on the debugger and single step back and forth, the two lines immediately above sets the property npv.CapturedIndex to {0,0}.
0
Comment
Question by:jdcoburn
  • 2
3 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 38776788
Assigning an array to another variable does not copy the values contained within the array. Arrays are reference types in .NET, and when you assign a reference type to anther variable, only the reference is copied. You have two references to the same array, therefore changes in one are reflected within the other. You might try using Array.Copy to create a clone of the array.
0
 

Author Comment

by:jdcoburn
ID: 38778681
yes, of course. thanks.
0
 

Author Closing Comment

by:jdcoburn
ID: 38778687
yes, of course. thanks.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now