M
Monty
Hope this is an easy one: How can I bind a text on a form to a an integer
variable? Possible? Thanks!
variable? Possible? Thanks!
Hope this is an easy one: How can I bind a text on a form to a an integer
variable? Possible? Thanks!
Well, you would want to, because you have 20 fields, and you don't want
code manually updating the 20 variables all the time. It is for the same
reasons you would want to bind to an actual datasource.
Monty said:Hope this is an easy one: How can I bind a text on a form to a an integer
variable? Possible? Thanks!
Marina Levit said:You can argue that if you update the data source, update the display too.
It's not any harder to update a row in a datatable then it is to update a
variable as a developer. Of course multi-row datasources provide other
benefits too - but those are not always necessary.
Obviously, binding to a variable can't be done for technical reasons. But
I don't agree that it wouldn't be convenient in some cases.
Convenience. Why would I want to write all those event handlers?
Also, it's the other way around... I want to update the variable when the
user changes the control's value.
Jim Hughes said:To a varialbe directly, don't think so...
But to a form property, yes
' Add a button to a form, paste code behind below
'VB.Net 2005 code
Public Class Form1
Implements System.ComponentModel.INotifyPropertyChanged
Public Event PropertyChanged(ByVal sender As Object, _
ByVal e As System.ComponentModel.PropertyChangedEventArgs) _
Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Private _pageno As Integer = 1
<System.ComponentModel.Bindable(True)> _
Public Property PageNo() As Integer
Get
Return _pageno
End Get
Set(ByVal value As Integer)
_pageno = value
RaiseEvent PropertyChanged(Me, New
System.ComponentModel.PropertyChangedEventArgs("PageNo"))
End Set
End Property
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles MyBase.Load
' updates form title whenever PageNo is changed
Me.DataBindings.Add(New Binding("Text", Me, "PageNo"))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles Button2.Click
' Increment PageNo
Me.PageNo += 1
End Sub
End Class ' Form1