Solved

how a user control updates its properties

Posted on 2013-01-14
3
264 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
[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
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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