all groups > vb.net > february 2006 >
You're in the

vb.net

group:

DataBindings Help


DataBindings Help Andrew Bassett
2/28/2006 6:12:44 PM
vb.net:
Hey everyone...
I have what I hope is a simple question. I have a form with about a dozen
controls bound to a databinding source. That datasource is bound to a
dataset. Without using a binding navigator, how do I do anything with this
thing?? I can't for the life of me figure out how to add, update, etc... Is
this possible without the navigator?

Thanks!!

RE: DataBindings Help lukezhan NO[at]SPAM online.microsoft.com
3/1/2006 2:09:59 AM
Hello,

BindingSource component provide some method to add, update records, for
example, to add a record, call AddNew() method; to update, call EndEdit()
method; to remove a record, call remove() mthod. All these can be done
without a navigator.

Hope this help,

Luke Zhang
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Re: DataBindings Help Andrew Bassett
3/1/2006 1:34:48 PM
When I try to make this work I run into a problem. I call addnew and then
should be able to call endedit. However, when I do that I keep getting an
error kicked back about null values for columns. This happens with or
without data in my columns. Why is it its not recognizing the values I put
in my text boxes?? Does this make sense? As an example...

If I have a text box called Key and I put something in it I get a null
reference error. But, if after calling AddNew I set the value of my textbox
via code then it recognizes that value.

It seems like maybe I broke something with my databinding but it half way
works ...


[quoted text, click to view]

Re: DataBindings Help Andrew Bassett
3/1/2006 2:14:13 PM
I think my problem was the lack of the CurrencyManager. I don't have one of
those anywhere ... Thanks for the quick reply, I'm off to explore.


[quoted text, click to view]

Re: DataBindings Help Andrew Bassett
3/1/2006 2:38:36 PM
On your example you have the following line....

cma =3D DirectCast(BindingContext(dt), CurrencyManager)

I'm having trouble making that work. If I try this...

cma =3D DirectCast(Me.Sites_MBindingSource, CurrencyManager)

I get an error stating I cannot convert a binding source to a Currency =
Manager. How can I make that work?



[quoted text, click to view]
http://www.vb-tips.com/default.aspx?ID=3Dc6c7d9a8-7511-41a1-a488-2e91e529=
5e7c
[quoted text, click to view]
Re: DataBindings Help Cor Ligthert [MVP]
3/1/2006 8:08:38 PM
Andrew,

Was it you that I showed yesterday this sample on our website?

http://www.vb-tips.com/default.aspx?ID=c6c7d9a8-7511-41a1-a488-2e91e5295e7c

Otherwise I hope this helps,

Cor


"Andrew Bassett" <Flesrouy@community.nospam> schreef in bericht
news:O8NpW7VPGHA.3196@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view]

Re: DataBindings Help lukezhan NO[at]SPAM online.microsoft.com
3/2/2006 2:47:23 AM
In my test, after call Addnew, the TextBox is changed to blank and I can
type some string in it. Then I click a button to call
bindingSource1.EndEdit() and this work.

Are all of the fileds in bindingSource bound to a control on the form?
Before EndEdit(), is each of these controls has a actual value? When you
get the exception like

Column 'abc' does not allow nulls.

You may check if the field 'abc' is bound to a control (for example, a
TextBox) and if it has a actual value


Luke Zhang
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Re: DataBindings Help Mike Mudliar a.k.a Mudmike
3/18/2006 4:25:45 AM
You can do same thing without Navigator by using –


'Moves data item First
Private Sub btnMoveFirst_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMoveFirst.Click
Me.BindingContext(DA, "Employee").Position = 0
End Sub
'Moves data item Last
Private Sub btnMoveLast_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMoveLast.Click
Me.BindingContext(DA, "Employee").Position = Me.BindingContext(DA,
"Employee").Count - 1
End Sub
'Moves data item Next
Private Sub btnMoveNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMoveNext.Click
Me.BindingContext(DA, "Employee").Position -= 1
End Sub
'Moves data item Prev
Private Sub btnMovePrev_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMovePrev.Click
Me.BindingContext(DA, "Employee").Position += 1
End Sub
'Add New item
Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddNew.Click
Dim instance As BindingNavigator
Dim value As ToolStripItem
value = instance.AddNewItem
instance.AddNewItem = value
End Sub
'Delete item
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDel.Click
Dim instance As BindingNavigator
Dim value As ToolStripItem
value = instance.DeleteItem
instance.DeleteItem = value
End Sub
Re: DataBindings Help mikeinthemud NO[at]SPAM gmail.com
3/31/2006 11:57:54 PM
You can do the same without Navigator by using –
'Moves data item First
Private Sub btnMoveFirst_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMoveFirst.Click
Me.BindingContext(DA, "TBL").Position = 0
End Sub
'Moves data item Last
Private Sub btnMoveLast_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMoveLast.Click
Me.BindingContext(DA, "TBL").Position = _
Me.BindingContext(DA,"TBL").Count - 1
End Sub
'Moves data item Next
Private Sub btnMoveNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMoveNext.Click
Me.BindingContext(DA, "TBL").Position -= 1
End Sub
'Moves data item Prev
Private Sub btnMovePrev_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMovePrev.Click
Me.BindingContext(DA, "Employee").Position += 1
End Sub
'Add New item
Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddNew.Click
Dim instance As BindingNavigator
Dim value As ToolStripItem
value = instance.AddNewItem
instance.AddNewItem = value
End Sub
'Delete item
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDel.Click
Dim instance As BindingNavigator
Dim value As ToolStripItem
value = instance.DeleteItem
instance.DeleteItem = value
End Sub

As an alternative download IdeaBlade’s DevForce Express and use that for ORM (I don’t work for them – but use it extensively)
AddThis Social Bookmark Button