473,398 Members | 2,188 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,398 software developers and data experts.

Easy One: Bind a Text Box to a an Integer Variable

Hope this is an easy one: How can I bind a text on a form to a an integer
variable? Possible? Thanks!
Apr 3 '06 #1
12 5854
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.

"Monty" <mo***@community.nospam> wrote in message
news:ej**************@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!

Apr 3 '06 #2

"Monty" <mo***@community.nospam> wrote in message
news:ej**************@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.


Apr 3 '06 #3
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" <no****@nowhere.com> wrote in message
news:tzdYf.24774$Ph4.21405@edtnps90...

"Monty" <mo***@community.nospam> wrote in message
news:ej**************@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.

Apr 3 '06 #4

"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:ei**************@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.

Apr 3 '06 #5
"Monty" <mo***@community.nospam> schrieb:
Hope this is an easy one: How can I bind a text on a form to a an integer
variable? Possible? Thanks!


Not directly, but what's the problem to parse the string using
'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/>

Apr 3 '06 #6
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" <no****@nowhere.com> wrote in message
news:GPeYf.24792$Ph4.3479@edtnps90...

"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:ei**************@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.

Apr 3 '06 #7
> ??? 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.

Apr 3 '06 #8
Bummer. Thanks for the insight!

"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:eN****************@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" <no****@nowhere.com> wrote in message
news:GPeYf.24792$Ph4.3479@edtnps90...

"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:ei**************@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.


Apr 3 '06 #9

"Monty" <mo***@community.nospam> wrote in message
news:%2****************@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?
How many?
Also, it's the other way around... I want to update the variable when the
user changes the control's value.


Why not a NumericUpDown control?

Apr 3 '06 #10
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.Prope rtyChanged

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("Pa geNo"))
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" <mo***@community.nospam> wrote in message
news:ej**************@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!

Apr 3 '06 #11
Interesting, thanks Jim.

"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:%2****************@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.Prope rtyChanged

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("Pa geNo"))
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" <mo***@community.nospam> wrote in message
news:ej**************@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!


Apr 4 '06 #12
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

"Monty" <mo***@community.nospam> schreef in bericht
news:ej**************@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!

Apr 4 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Oliver Bryant | last post by:
I just finished developing a javascipt component allowing floating captions to appear over HTML elements. If anyone wants to check it out you can see specs and download it from...
7
by: Sashi | last post by:
Two questions: (1) I can pull the text of an XML element as a string just fine using code as such: strSomeString = myXmlDoc.SelectSingleNode("/Element1/Element2/Element3",...
9
by: Mark Walsh | last post by:
The following is an explanation of a bug that exists in the VB.NET compiler. I've tried to report it to Microsoft, but they've made it so difficult I've given up: MSDN help states that variables...
6
by: Mark Walsh | last post by:
The following is an explanation of a bug that exists in the VB.NET compiler. I've tried to report it to Microsoft, but they've made it so difficult I've given up: MSDN help states that variables...
1
by: Mad Scientist Jr | last post by:
can someone explain how to simply populate a grid in .net ? the way i understand it, there is no more msflexgrid, and instead is this new control that has to be tied to a dataset, and it is a real...
3
by: AH | last post by:
Hi all, I noticed this strange behavior; I created a new control (example inherits from textbox) and add a new property, then I bind this new property to a field in my dataTable in a dataSet....
2
by: Zamael | last post by:
So here's what I got: Datagrid with multiple controls but the ones in question are 3 labels. Basically the three labels should be showing data pulled from a database. To complicate things, the...
2
by: duancg | last post by:
Hi, I wonder if someone could help since I wasn't able to find the answer through search. I have a simple .aspx page that shows data from a database table, as a table in UI. Now the data uses...
1
by: =?Utf-8?B?Rml4ZXI=?= | last post by:
There is Content Management System. In it on administrator's side dinamic number of "body" (which showing in FCKeditors) elements for generating page Code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.