I think you are correct, in your implementation you put a new item in the list, replacing an old one I would guess this raises the SelectedIndexChanged event. There are a couple of solutions, you could make your document object mutable so you can just change the text itself rather than the whole object:

1
2
3
4
5
6
7
    type Document = {filename: string; mutable text: string;}

    do lstProject.SelectedIndexChanged.Add(fun _ ->
            documentList.Item(prevSelection).text <- txtEditor.Text;
            prevSelection = lstProject.SelectedIndex;
            txtEditor.Text <- documentList.Item(lstProject.SelectedIndex).text
        )

Or you could create sort of an update lock:

1
2
3
4
5
6
7
8
9
10
11
    let mutable updatingDoc = false

    do lstProject.SelectedIndexChanged.Add(fun _ ->
            if not updatingDoc then begin
                updatingDoc <- true
                use updateLock = { new IDisposable with Dispose() = updatingDoc <- false };
                documentList.Item(prevSelection).text <- txtEditor.Text;
                prevSelection = lstProject.SelectedIndex;
                txtEditor.Text <- documentList.Item(lstProject.SelectedIndex).text
            end
        )

Be aware I haven't tested either idea.

By on 3/7/2008 3:05 AM ()

I've implemented the first and it works. I also needed to make prevSelection mutable as well (which it wasn't before). I haven't tried the second but the logic sounds about right (famous last words :) ).

By on 3/7/2008 8:19 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper