473,507 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

winforms: Bind int to a control

I have a text box and I simply want to bind it to an int variable. I'm
testing how all this stuff works and I wanted to test if I increment the
int, will the textbox update automatically, however I didn't get far cause I
can't get binding to work with an int OR I should say it wants an object and
a member..

Any tips or heads-ups?

Thanks-
Steve
Nov 16 '05 #1
3 4505
Steve,

You won't be able to do this. You will need an object that stores the
int, and exposes it as a property, also firing an event when it changes. An
int is a value type, and doesn't have any mechanism to indicate when the
value changes.

Your only choice would be to create an object with a property that
exposes this, and an event that fires (named correctly <property
name>Changed of type EventHandler) when the property changes.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SteveK" <as***@asdfasdfsd.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
I have a text box and I simply want to bind it to an int variable. I'm
testing how all this stuff works and I wanted to test if I increment the
int, will the textbox update automatically, however I didn't get far cause
I
can't get binding to work with an int OR I should say it wants an object
and
a member..

Any tips or heads-ups?

Thanks-
Steve

Nov 16 '05 #2
Thanks Nicholas,

I switched over to just use a DataTable, I figure it's all built in and for
testing purposes it would be easier ;)

Thanks for the quick response though!.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
Steve,

You won't be able to do this. You will need an object that stores the
int, and exposes it as a property, also firing an event when it changes. An int is a value type, and doesn't have any mechanism to indicate when the
value changes.

Your only choice would be to create an object with a property that
exposes this, and an event that fires (named correctly <property
name>Changed of type EventHandler) when the property changes.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SteveK" <as***@asdfasdfsd.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
I have a text box and I simply want to bind it to an int variable. I'm
testing how all this stuff works and I wanted to test if I increment the
int, will the textbox update automatically, however I didn't get far cause I
can't get binding to work with an int OR I should say it wants an object
and
a member..

Any tips or heads-ups?

Thanks-
Steve


Nov 16 '05 #3
Hi Steve,

You can bind it to a property that reflects an int

private int myint = 0;
public int Val
{
get { return myint; }
set { myint = value; }
}
textBox1.DataBindings.Add("Text", this, "Val");

This will initially update the textbox and any later changes to the textbox will be stored in the int. However, if you change the int internally it will not update the textbox. If you do that, you need to update the textbox by calling ReadValue on the databinding

textBox1.DataBindings["Text"].ReadValue();
--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #4

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

Similar topics

10
2381
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
5
1840
by: Dan Smith | last post by:
Right now the only way to use a WinForms control in MFC is to enable COM Interop for the control and use it in MFC as you would any ActiveX control. While this works, COM Interop is a pain, and an...
3
1810
by: Tom S. | last post by:
VS.Net 2003 V 7.1.3088 ..Net Framework V 1.1.4322 SP1 WinXP SP2 I have a WinForms project that I'm having trouble with. I have a custom user control ( all code based, no visual ) and another...
5
4062
by: Segfahlt | last post by:
I need a little help here please. I have 2 win forms user controls in 2 different projects that I'm hosting in 2 different virtual directories. The controls have been test and operate okay in...
1
8512
by: Pieter | last post by:
Hi, In my application VB.NET 2005 application I placed a ReportViewer, and link it to a server-report: Me.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote...
0
1692
by: elbetzio | last post by:
Evening, I've got a highly irritating bug with the reportviewer control that appears to be a show-stopper for one of our bigger applications we're writing. When I try and print more than 1...
1
10932
by: sklett | last post by:
I've setup the simplest of tests; A form with a ListBox and a Button. The ListBox is bound to a List<string>. When you click the Button, a new string is added to the list. I can't for the life...
2
1522
by: John Sheppard | last post by:
Hello there, I have a dataset on a form...I shall call the host form. I also have a user control with a whole bunch of textboxes and gridviewcontrols on it. I shall call this the leech form. ...
1
6153
by: renuami | last post by:
Hello Please advise .... I do not know in which section i should be posting Winforms Questions. There is not Option. So i am posting it here... apologize for any inconvinence..... This is...
0
7223
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
7114
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
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.