When I try to set IsNew on the BindingSource having the custom IBindingListView, the BindingSource IsNew remaines false.
I have been able to do a test with my own IBindingListView being set on the BindingSource, and if I set IsNew before I set my DataSource, IsNew is True.
Here's a couple functions I have tried to set it to IsNew, but the first one removes the DataSource, but after setting it back, the DataSource is Nothing. The second one doesn't do anything, but is more in the lines of how I would like to set IsNew.
Expand|Select|Wrap|Line Numbers
- ' What I am trying to do
- Public Sub FooBindingSourceIsNew(Source As BindingSource, IsNew As Boolean)
- ....' This remains the same value as before, since the Source.DataSource has a value
- ....Source.IsNew = IsNew
- End Function
Expand|Select|Wrap|Line Numbers
- ' Try 1
- Public Sub FooBindingSourceIsNew(Source As BindingSource, IsNew As Boolean)
- ....'This leaves me with Source.DataSource = Nothing
- ....Dim TmpDataMember As String = Source.DataMember
- ....Dim TmpDataSource As Object = Source.DataSource
- ....Source.DataSource = Nothing
- ....Source.DataMember = ""
- ....Source.IsNew = IsNew
- ....Source.DataMember = TmpDataMember
- ....Source.DataSource = TmpDataSource
- End Function
Expand|Select|Wrap|Line Numbers
- ' Try 2
- Public Sub FooBindingSourceIsNew(Source As BindingSource, IsNew As Boolean)
- ....'This does nothing different than leaving Source.IsNew as it's previous value
- ....Source.ResetBindings(False)
- ....Source.IsNew = IsNew
- ....Source.ResetBindings(True)
- End Function
The real code is tied into a project I am working on for work, which is embedded in a derived DataGridView->TypedDataGridViewT(Of T As Foo, U As Collection(Of T))--to be strongly typed.
So anyone using my grid will be able to pass in a DataSource, where I handle it and most of the time wrap a BindingSource around it. A few times a BindingSource is passed which is ok as well. But when it's a BindingSource which has IsNew false, and AllowUsersToAddRows is true, it causes grief for people using my grid.
I've probably talked too much, but it's been a while since I've been on here, and code crunch time will soon be over.
Hopefully Helpful,
TamusJRoyce