Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how a user control updates its properties

Posted on 2013-01-14
3
Medium Priority
?
269 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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 …
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

885 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