CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2011
    Location
    .Net 4.0
    Posts
    39

    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.

  2. #2
    Join Date
    May 2012
    Location
    Bonn, Germany
    Posts
    43

    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);

  3. #3
    Join Date
    Dec 2011
    Location
    .Net 4.0
    Posts
    39

    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
  •  





Click Here to Expand Forum to Full Width

Featured