-
May 21st, 2012, 01:00 AM
#1
Clone CheckedListBox.CheckedIndices
I am writing a custom CheckedListBox control, where part of its purpose will be to compare changes to Checked status of items with the status of those items when the control was first initialized (basically, see if any changes were made).
I have 2 properties of this control:
1. CheckedIndices
2. InitialCheckedIndices
After I declare the custom control, I set checked status of various items. Once I have completed this, I want to do this:
customCheckedListBox1.InitialCheckedIndices = customCheckedListBox1.CheckedIndices
Of course, the problem is that the former is merely a reference to the latter, and every time the latter is changed by the user, the former is changed with it.
Is there a nice, minimalist way to make InitialCheckedIndices a copy of CheckedIndices WITHOUT reference?
Thanks.
-
May 21st, 2012, 04:50 AM
#2
Re: Clone CheckedListBox.CheckedIndices
CheckedIndexCollection has no public constructor, so you can't create an instance of it. But you can do an array.
Code:
int[] checkedIndicesCopy = new int[checkedIndices.Count];
checkedIndices.CopyTo(checkedIndicesCopy, 0);
-
May 21st, 2012, 01:26 PM
#3
Re: Clone CheckedListBox.CheckedIndices
I was aware of that function, but there does not appear to be a function that works in reverse order, so that the array is copied back in to the "non-reference" copy.
But anyway, I might not have explained well enough. The idea is to have a control, which is as fully self-contained as possible, where inside its class, it can monitor whether a change was made to it.
It is easy to monitor a change, BUT..... What about when the user UNDOES the change, thereby rendering the value back equal to the control's ORIGINAL value?
To use pseudo-code:
If (this.Value!=this.OriginalValue)
Do something....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|