473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 4621
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

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

Similar topics

1
by: mali_djuro | last post by:
Hi all, i got problem vwith method session.isNew in WAS 5. i check is new session or not, and if it is i fill it with some data, and if it is not i make session.invalidate and check again. ...
3
by: silesius | last post by:
Hi All, I have two pagetabs. One pagetab is used to display a parent record and the other is suppose to display 3 related child records from another table. I can display the parent records just...
1
by: TN | last post by:
I just don't get the BindingSource class when it is bound to a class. Consider this code snip: ..... Private bSource As New BindingSource() Private dgv As New DataGridView() Public Sub New()...
0
by: Geoff | last post by:
Hi folks Calling BindingSource.ResetCurrentItem() is changing the BindingSource.Position in a way I don't understand. If I'm understanding the docs correctly, ResetCurrentItem() should simply...
4
by: shibeta | last post by:
Hello, I have problem with DataGridView and BindingSource. I have created DataSet and added TableData to it with manualy created columns (without DataAdapter - I'm not using MSSQL). On the Form I...
7
by: Mike | last post by:
i have a small difficulties with BindingSource and dataGridView bind db has properly opened and bind doesn't works. Unfortunately I didn't find any good example how to connect MS Access with...
0
nev
by: nev | last post by:
Have any of you encountered this? And how did you correct it? bs.addnew() automatically moves the position to the new record. But mine doesn't. I have 3 bindingsources in my program, all...
2
by: jehugaleahsa | last post by:
Hello: I'm working on improving some of our Windows Forms. I have created two user controls that I want to bind to the same BindingSource. I have an overview control that is used just to...
5
by: jehugaleahsa | last post by:
Hello: I am sure this question comes up a lot. I need to disable the controls on my Windows forms so that when the BindingSource is empty some the controls bound to it will be disabled. This...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.