Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how a user control updates its properties

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

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
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…

721 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