473,399 Members | 3,603 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.

Parse method never called when data binding from class property to textedit

I'm using C# and having problems getting the 'Parse' EventHandler of
my binding object to be called. Interestingly, the 'Format' method is
always called however. A code snippet:

(rdDocument is a private member field of the class and has a
string-type property called 'Name')

Binding bName = new Binding("Text", rdDocument, "Name");
bName.Format += new ConvertEventHandler(teName_Format);
bName.Parse += new ConvertEventHandler(teName_Validate);
textBox1.DataBindings.Add(bName);

private void teName_Format(object sender, ConvertEventArgs e)
{
<perform formatting, OK: method always called>
}

private void teName_Validate(object sender, ConvertEventArgs e)
{
string sValue = (string) e.Value;
<perform validation, PROBLEM: method never called>
}

Can anybody tell me why it's not being called or how I can force it to
be called? Help!
Rich
Nov 16 '05 #1
3 2026
Are you sure the data is getting commited to rdDocument.Name property
without the Parse event getting called. That would be strange indeed.

You may also try calling
teName.DataBindings["Text"].BindingManagerBase.EndCurrentEdit();
incase you are setting the text directly from code.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

Richard Urwin wrote:
I'm using C# and having problems getting the 'Parse' EventHandler of
my binding object to be called. Interestingly, the 'Format' method is
always called however. A code snippet:

(rdDocument is a private member field of the class and has a
string-type property called 'Name')

Binding bName = new Binding("Text", rdDocument, "Name");
bName.Format += new ConvertEventHandler(teName_Format);
bName.Parse += new ConvertEventHandler(teName_Validate);
textBox1.DataBindings.Add(bName);

private void teName_Format(object sender, ConvertEventArgs e)
{
<perform formatting, OK: method always called>
}

private void teName_Validate(object sender, ConvertEventArgs e)
{
string sValue = (string) e.Value;
<perform validation, PROBLEM: method never called>
}

Can anybody tell me why it's not being called or how I can force it to
be called? Help!
Rich

Nov 16 '05 #2
it turns out that i needed to do:

m_bName = teName.DataBindings.Add("Text", m_rdDocument, "Name");

and use this bindings object in the following way:

m_bName.Format += new ConvertEventHandler(teName_Format);
m_bName.Parse += new ConvertEventHandler(teName_Validate);

A bug in C#?

One more thing - i need to prevent the user entering an empty string,
but if the string is empty to start with and doesn't change, the parse
method doesn't get called.

any suggestions?

cheers,
rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
That's strange, i've never had to do it that way. As for the emtpy
string problem, what i usually do is give a default value for the
string, something like '<Name> ' or some other helpful hint.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

Richard Urwin wrote:
it turns out that i needed to do:

m_bName = teName.DataBindings.Add("Text", m_rdDocument, "Name");

and use this bindings object in the following way:

m_bName.Format += new ConvertEventHandler(teName_Format);
m_bName.Parse += new ConvertEventHandler(teName_Validate);

A bug in C#?

One more thing - i need to prevent the user entering an empty string,
but if the string is empty to start with and doesn't change, the parse
method doesn't get called.

any suggestions?

cheers,
rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4

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

Similar topics

0
by: CGuy | last post by:
URGENT HELP REQUIRED FROM GURUS Hi, I have a custom object that implements ICollection and IListSource. This object has also an enumerator defined for it which implements IEnumerator and...
24
by: | last post by:
Hi, I need to read a big CSV file, where different fields should be converted to different types, such as int, double, datetime, SqlMoney, etc. I have an array, which describes the fields and...
3
by: Kevin Kenny | last post by:
Dear All, I have a date time validation method thus: public static bool IsDate(string date, System.IFormatProvider provider) { try { DateTime.Parse(date, provider) return true; } catch...
3
by: Marty McDonald | last post by:
I have <asp:Table... </asp:Table> on my webform. In codebehind, I populate a DataTable whose data should appear in the asp:Table. I created my own code to populate the asp:Table with the...
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...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
2
by: cjard | last post by:
Suppose: A TextBox is bound to a BindingSource, which is bound to a DataTable A BindingNavigator is used to alter the current row being looked at by the BindingSource (i.e. Nav's NEXT button is...
4
by: sjkothenbeutel | last post by:
I've been reading through quite a bit regarding this topic but am finding myself confused. Here is the scenario: I have a javascript class defined with methods whereas each has references to...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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
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,...

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.