468,771 Members | 1,847 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

BindingSource IsNew

110 100+
I am working on a group project where I do not have access to a BindingSource that is being passed through a function. The BindingSource's DataSource is set to a custom IBindingListView Collection.

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
  1. ' What I am trying to do
  2. Public Sub FooBindingSourceIsNew(Source As BindingSource, IsNew As Boolean)
  3. ....' This remains the same value as before, since the Source.DataSource has a value
  4. ....Source.IsNew = IsNew
  5. End Function
  6.  
Expand|Select|Wrap|Line Numbers
  1. ' Try 1
  2. Public Sub FooBindingSourceIsNew(Source As BindingSource, IsNew As Boolean)
  3. ....'This leaves me with Source.DataSource = Nothing
  4. ....Dim TmpDataMember As String = Source.DataMember
  5. ....Dim TmpDataSource As Object = Source.DataSource
  6.  
  7. ....Source.DataSource   = Nothing
  8. ....Source.DataMember = ""
  9.  
  10. ....Source.IsNew = IsNew
  11.  
  12. ....Source.DataMember = TmpDataMember
  13. ....Source.DataSource  = TmpDataSource
  14. End Function
  15.  
Expand|Select|Wrap|Line Numbers
  1. ' Try 2
  2. Public Sub FooBindingSourceIsNew(Source As BindingSource, IsNew As Boolean)
  3. ....'This does nothing different than leaving Source.IsNew as it's previous value
  4. ....Source.ResetBindings(False)
  5.  
  6. ....Source.IsNew = IsNew
  7.  
  8. ....Source.ResetBindings(True)
  9. End Function
  10.  
Well, Try 2 is an obvious failure, but I was frustrated, so I tried it : )

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
Mar 5 '09 #1
2 4052
TamusJRoyce
110 100+
I'm assuming this form has became too hard to use for people to answer questions. I will be going elsewhere for helping people with and asking questions.

Thanks for everyones help that I've gotten in the past, and I may be back if this form ever recovers from its non-intuitive design...

TamusJRoyce
Mar 8 '09 #2
TamusJRoyce
110 100+
Found out the reason why IsNew could not be set on the DataSource. My DataSource was a BindingSource with BindingSource.DataMember = "Foo1" and also BindingSource.DataSource = BindingSourceFoo2, where BindingSourceFoo2.DataMember = "" and BindingSourceFoo2.DataSource = "Foo2".

Complicated, but really what was happening is the "Foo2"->"Foo1" pointed to my desired collection. The DataSource was bound to a Form which was causing this behavior, even though BindingSource.DataSource was explicitly being set to the desired collection.

So as a warning... BEWARE: BindingSources set graphically on a form handle DataSources strangely (well, how DataBinding does things behind the scenes). So BindingSource.DataSource = collection won't result in BindingSource.DataSource being a collection. So always explicitly define your own BindingSources.

.NET doing things behind the scenes against me again. :P

Hopefully Helpful,

TamusJRoyce
Mar 26 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by mali_djuro | last post: by
3 posts views Thread by silesius | last post: by
5 posts views Thread by jehugaleahsa | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.