|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Easy One: Bind a Text Box to a an Integer VariableHope this is an easy one: How can I bind a text on a form to a an integer
variable? Possible? Thanks! No, you cannot bind to a variable.
Binding works for collections that implement an interface such that the objects doing the binding can property get data in and out of the source object. It can't be done with just a given variable. Show quoteHide quote "Monty" <monty@community.nospam> wrote in message news:ej5IZxzVGHA.4792@TK2MSFTNGP14.phx.gbl... > Hope this is an easy one: How can I bind a text on a form to a an integer > variable? Possible? Thanks! > "Monty" <monty@community.nospam> wrote in message ??? Why would you want to? Just update it when the variable changes.news:ej5IZxzVGHA.4792@TK2MSFTNGP14.phx.gbl... > 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. "Homer J Simpson" <nob***@nowhere.com> wrote in message news:tzdYf.24774$Ph4.21405@edtnps90...Show quoteHide quote > > "Monty" <monty@community.nospam> wrote in message > news:ej5IZxzVGHA.4792@TK2MSFTNGP14.phx.gbl... > >> Hope this is an easy one: How can I bind a text on a form to a an integer >> variable? Possible? Thanks! > > ??? Why would you want to? Just update it when the variable changes. > > > > "Marina Levit [MVP]" <someone@nospam.com> wrote in message Binding to a data source is logical. Binding to a program variable is odd. news:ei3HJ20VGHA.4308@TK2MSFTNGP12.phx.gbl... > 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. If you update the variable, update the display. 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. "Homer J Simpson" <nob***@nowhere.com> wrote in message news:GPeYf.24792$Ph4.3479@edtnps90...Show quoteHide quote > > "Marina Levit [MVP]" <someone@nospam.com> wrote in message > news:ei3HJ20VGHA.4308@TK2MSFTNGP12.phx.gbl... > >> 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. > > Binding to a data source is logical. Binding to a program variable is odd. > If you update the variable, update the display. > > > Bummer. Thanks for the insight!
Show quoteHide quote "Marina Levit [MVP]" <someone@nospam.com> wrote in message news:eNsm%23b1VGHA.4720@TK2MSFTNGP15.phx.gbl... > 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. > > "Homer J Simpson" <nob***@nowhere.com> wrote in message > news:GPeYf.24792$Ph4.3479@edtnps90... >> >> "Marina Levit [MVP]" <someone@nospam.com> wrote in message >> news:ei3HJ20VGHA.4308@TK2MSFTNGP12.phx.gbl... >> >>> 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. >> >> Binding to a data source is logical. Binding to a program variable is >> odd. If you update the variable, update the display. >> >> >> > > > ??? Why would you want to? Just update it when the variable changes. 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. "Monty" <monty@community.nospam> wrote in message How many?news:%23JNmi21VGHA.4596@TK2MSFTNGP15.phx.gbl... >> ??? Why would you want to? Just update it when the variable changes. > 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 Why not a NumericUpDown control?> user changes the control's value. "Monty" <monty@community.nospam> schrieb: Not directly, but what's the problem to parse the string using > Hope this is an easy one: How can I bind a text on a form to a an integer > variable? Possible? Thanks! 'Integer.{Parse, TryParse}' and assign it to a private backup field in the control's 'Validating' event? -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> 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 Show quoteHide quote "Monty" <monty@community.nospam> wrote in message news:ej5IZxzVGHA.4792@TK2MSFTNGP14.phx.gbl... > Hope this is an easy one: How can I bind a text on a form to a an integer > variable? Possible? Thanks! > Interesting, thanks Jim.
Show quoteHide quote "Jim Hughes" <NOSPAMJ3033@Hotmail.com> wrote in message news:%23eDQQr2VGHA.5468@TK2MSFTNGP14.phx.gbl... > 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 > > "Monty" <monty@community.nospam> wrote in message > news:ej5IZxzVGHA.4792@TK2MSFTNGP14.phx.gbl... >> Hope this is an easy one: How can I bind a text on a form to a an integer >> variable? Possible? Thanks! >> > > Monty,
I think that there are a lot of easier solution to keep track on a changed textbox, however. You can create a bindable collection with only one integer value in that. Protect it that the index of the collection can only be zero. Than you can bind that collection which holds your to your control. I would not do that. Cor Show quoteHide quote "Monty" <monty@community.nospam> schreef in bericht news:ej5IZxzVGHA.4792@TK2MSFTNGP14.phx.gbl... > Hope this is an easy one: How can I bind a text on a form to a an integer > variable? Possible? Thanks! >
How do you use an unbound DataAdapter?
Trying to "display" control characters in a text box Getting the selected item from a listview Dummy question Getting DataGrid row X, Y position and Changing Column Width (2003) WMI script to get Win32_Product Where to do the Loading tasks for application ? Foreign Language Names Can't get rid of references Using PLink interactively as a Telnet process with VB.Net 2003 |
|||||||||||||||||||||||