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

Binding to my property??? How???

I would like to write a class that has property, for example, MyText and I
want to be able to bind a Text property of a TextBox to my MyText property.
When I change the value of MyText property in my class that change should be
visible in binded control. How can I do this?

Thx.

P.S. This is just an example. I'm trying to make a property to witch I could
bind other visible components. Like when I bind Text property of textbox1 to
Text property of textbox2, and when I type something in textbox2 it appears
in textbox1. I hope I was clear enough what I'm trying to do. Thx again.
Nov 15 '05 #1
3 4992
"Vlatko" <vl************@fer.hr> wrote in
news:uQ**************@TK2MSFTNGP11.phx.gbl:
I would like to write a class that has property, for example, MyText and
I want to be able to bind a Text property of a TextBox to my MyText
property. When I change the value of MyText property in my class that
change should be visible in binded control. How can I do this?


Just create a class with a property MyText and bind it to the
textbox as:

myTextBox.DataBindings.Add("Text", myObjectToBind, "MyText");

To be sure that changes are propagated, you have to define the
event MyTextChanged in the class with the property MyText as well. This
event can be a simple event:

public event EventHandler MyTextChanged;

Then when the value MyText should return changes, you simply raise
that event when there are subscribers:

private string _myText;

public event EventHandler MyTextChanged;

//..

public string MyText
{
get { return _myText; }
set
{
_myText=value;
if(MyTextChanged!=null)
{
MyTextChanged(this, New EventArgs());
}
}
}

the datbinding logic in the controls will bind to the Changed event if
they're binded to a property with the same name. When the event is fired,
they'll refresh themselves with the new value.

FB

--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
Nov 15 '05 #2
Frans,
the datbinding logic in the controls will bind to the Changed event if
they're binded to a property with the same name. When the event is fired,
they'll refresh themselves with the new value.

Is this property/event name convention described somewhere in MSDN? In other
words, can one safely rely on this naming scheme as an "official" one?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Nov 15 '05 #3
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in news:#o**************@TK2MSFTNGP10.phx.gbl:
Frans,
the datbinding logic in the controls will bind to the Changed event if
they're binded to a property with the same name. When the event is
fired, they'll refresh themselves with the new value.

Is this property/event name convention described somewhere in MSDN? In
other words, can one safely rely on this naming scheme as an "official"
one?


Unfortunately, it's the official one :) You're looking for 'simple
databinding'. You can find examples of that in the MSDN or online at the
MSDN site.

I say 'unfortunately' because if you have 20 properties, you have
to add 20 events, while it would have been better if there was just 1
event which had the property descriptor of the property that was changed.
That way it would be more flexible. Ah well. :)

FB

--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
Nov 15 '05 #4

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

Similar topics

6
by: Scott Mueller | last post by:
I have a question about simple binding: (please forgive any syntax errors... I am at home, where I do not have Vb.Net installed, and I rely far too much on Vb's intellisense!) If I have two...
11
by: Rourke Eleven | last post by:
I have looked and searched. What good is the databind property on Radiobuttons? How does one go about actually using it? What is a good resource on this? I understand that I can easily get/set...
19
by: Simon Verona | last post by:
I'm not sure if I'm going down the correct route... I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this...
0
by: Larry Serflaten | last post by:
I am not sure how many are aware of this sort of data binding, but as it is new to many (classic) VB developers I thought I would post this once just to let people know of its availablility. ...
0
by: JSantora | last post by:
Essentially, InsertAT is broken! For the past couple of hours, I've been getting this "Parameter name: '-2147483550' is not a valid value for 'index'." error. Apparently, its caused by having...
3
by: gregory_may | last post by:
I want to prevent late binding of this statement: MyServerConnections(Myindex).client = Value But when I try with the code below, I get an editor error: "Expression is a value and therefor...
6
by: Mikus Sleiners | last post by:
Is there any way to enable exception throws in VS 2005, that occur during binding operations? I am upset that i can't see exceptions that are thrown during binding operations. It's very hard to...
5
by: star-italia | last post by:
My XAML is the following: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style...
7
by: Steve K | last post by:
First problem: I am specifying a format string for a Binding object like so: <code> Binding binding = new Binding("Text", item.EOBRemittance, "AmountAllowed", true, DataSourceUpdateMode.Never,...
4
by: =?Utf-8?B?Y2xhcmE=?= | last post by:
Hi all, what is the difference between the late binding and reflection? clara -- thank you so much for your help
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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.