IsDirty within a SortedBindingListIsDirty within a SortedBindingList
Old forum URL: forums.lhotka.net/forums/t/2361.aspx
bgilbert posted on Friday, February 16, 2007
In a WinForm, I wrap a collection object in a sortedBindingList to allow sorts in a DataGridView. I'm trying to evaluate the collection's IsDirty property, but I'm struggling with the syntax to get to the original collection object.
Thanks,
Barry
JoeFallon1 replied on Friday, February 16, 2007
The original collection is still in a variable in your code. You used it when you created the sorted list.
So do not try and get it out of the sorted list. Just use the original variable.
Joe
bgilbert replied on Friday, February 16, 2007
Joe,
Thanks for your response. I should have been more explicit in my description.
I have subclassed the WinPart control (called MaintWinPart) to handle a variety of my forms. This control contains the bindingList, which I fill in the derived controls. I have the close routine in MaintWinPart handle the close/cancel logic by evaluating the BindingSource like this:
Public Overrides Sub Close(ByVal sender As Object, ByVal e As FormClosingEventArgs)
If Not (BindingSource1.DataSource Is Nothing) AndAlso BindingSource1.DataSource.IsDirty Then
Select Case MessageBox.Show("Save changes?", "Confirm close", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3)
Case DialogResult.Yes ' Save and close.
Save()
MyBase.Close(sender, e)
Case DialogResult.No ' Close without saving.
MyBase.Close(sender, e)
Case DialogResult.Cancel
e.Cancel = True
End Select
Else ' Not dirty.
MyBase.Close(sender, e)
End If
End Sub
My idea is to standardize the logic across all derived forms with the assumption that the BindingSource's DataSource is based on a BusinessListBase. However, when I started wrapping the collection classes in SortedBindingLists, I can no longer seem to use generic code to determine the IsDirty status.
RockfordLhotka replied on Friday, February 16, 2007
That's an interesting issue. SortedBindingList and FilteredBindingList should probably have a property allowing you to get at the original list...
They actually do - the SyncRoot property simply returns the original list reference - but there should be a more explicit way to do it (you can't count on SyncRoot for this particular purpose).
I'll add this to the wish list.
bgilbert replied on Friday, February 16, 2007
Rocky,
SyncRoot works for me for now.
Thanks for your response.
Barry
amselem replied on Friday, February 16, 2007
I also had this issue so I created a Generic class inherited from SBL to allow access to the inner list and to have strong typing :
Public Class SortedBindingListEx(Of TList As Generic.IList(Of TItem), TItem)
Inherits CSLA.SortedBindingList(Of TItem)
Public Sub New(ByVal list As TList)
MyBase.New(list)
Me.mSource = list
End Sub
Private mSource As TList = Nothing
Public ReadOnly Property List() As TList
Get
Return Me.mSource
End Get
End Property
End Class
Copyright (c) Marimer LLC