BrightIdeasSoftware.DataSourceAdapter.HandleListViewSelectedIndexChanged C# (CSharp) Method

HandleListViewSelectedIndexChanged() protected method

Handle the selection changing in our ListView. We need to tell our currency manager about the new position.
protected HandleListViewSelectedIndexChanged ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        protected virtual void HandleListViewSelectedIndexChanged(object sender, EventArgs e)
        {
            // Prevent recursion
            if (this.isChangingIndex)
                return;

            // If we are bound to a datasource, and only one item is selected,
            // tell the currency manager which item is selected.
            if (this.ListView.SelectedIndices.Count == 1 && this.CurrencyManager != null) {
                try {
                    this.isChangingIndex = true;

                    // We can't use the selectedIndex directly, since our listview may be sorted.
                    // So we have to find the index of the selected object within the original list.
                    this.CurrencyManager.Position = this.CurrencyManager.List.IndexOf(this.ListView.SelectedObject);
                } finally {
                    this.isChangingIndex = false;
                }
            }
        }