Mental Block

M

MS public

I'm trying to do something very simple, and I cant get it to work. Probably
last nights beero or possibly inherent stupidity on my part. Any how this
does not work. Any Ideas ? The PositionChanged event does not seem to fire
when I change the position of the bound Textbox.

TIA

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

myStrings(0) = "A"

myStrings(1) = "String"

myStrings(2) = "Array"

AddHandler Me.BindingContext(myStrings).PositionChanged, AddressOf
Me.onPositionChanged

End Sub

Private Sub onPositionChanged(ByVal Sender As System.Object, ByVal e As
System.EventArgs)

MessageBox.Show("Position Changed")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

TextBox1.DataBindings.Add("Text", myStrings, "")

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Me.BindingContext(myStrings).Position += 1

End Sub
 
K

Ken Tucker [MVP]

Hi,

Dim WithEvents cm As CurrencyManager

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim arText(3) As String

arText(0) = "zero"

arText(1) = "one"

arText(2) = "two"

arText(3) = "three"

TextBox1.DataBindings.Add("Text", arText, "")

cm = CType(Me.BindingContext(arText), CurrencyManager)

End Sub

Private Sub cm_PositionChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cm.PositionChanged

MessageBox.Show(String.Format("Position Changed to {0}", cm.Position))

End Sub



Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNext.Click

Dim x As Integer = cm.Position + 1

If Not x = cm.Count Then

cm.Position += 1

End If

End Sub

Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrev.Click

If cm.Position >= 0 Then

cm.Position -= 1

End If

End Sub



Ken
 
M

MS public

Ok, thanks Ken.

Now why didnt my AddHandler work, because it sees the event AddHandler
Me.BindingContext(myStrings).PositionChanged, when you write the code.
However, when I added the code for the currency manager, your event fired
and so did mine.

Regards - OHM
 
G

Gary

I am new to VB.NET and I'm trying to figure out this
code. I did a cut and paste in a sample project, but I
don't understand a few things. Why the following line:

cm = CType(Me.BindingContext(arText), CurrencyManager)

Can you explain what this exactly does? Once a textbox
is bound to data, why do you need this code.

Sorry for being such a "bonehead" but I'm trying to
understand it all.

Thanks

Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top