Solved

how a user control updates its properties

Posted on 2013-01-14
3
257 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 75

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

17 Experts available now in Live!

Get 1:1 Help Now