TextBox databinding (using endcurrentedit)

J

John Hui

Hi,

I have a .NET textbox bound to a DataColumn (String data
type). What I want is that when the the user leaves the
focus from the textbox, the changes are automatically
updated to the the DataTable (ie containing the
Datacolumn to which the textbix is bound).

The method I use is to call the 'EndCurrentEdit' method
for the corresponding CurrencyManager.

This method works fine except under the following
condition:

The textbox undergoes a modification such that the length
of the Text property in the TextBox does not change (ie
is the same as that of the String in the DataColumn).
This happens for example when a user makes a type and
changes one letter (or two) instead of adding new words
or deleting words. In this case, the datarowview
(referenced by the 'Current' property in the
corresponding CurrencyManager) is not in edit mode
(ie 'IsEdit' is false). Calling 'EndCurrentEdit' will
not update the DataColumn at all.

Can anyone confirm this is a .NET bug? Is there a
workaround for this? Does this happen in any other .Net
controls?

Thanks in advance. A sample code is available.
John
 
J

John Hui

Hi Miha,

Yes. That's one detail I left out. I call it in the
Validating event handler for the TextBox and I set it
to 'Cause Validation'.

The method works most of the time except when you change
say, one letter in the TextBox.

John
 
M

Miha Markic

Hi John,

I've sent you a test project via e-mail.
Try reproducing the behaviour if you can so I can understand better where
the problem is.
 
T

Tian Min Huang

Hello John,

Thanks for your post. Could you post a simple project which is able to
reproduce the problem? I will be glad to check it on my side.

I look forward to hearing from you.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

John Hui

Hi,

I have received the sample project from Miha and have
tried to reproduce the problem. I am happy to say that I
believe I goofed up.

In the Validating event handler, I do a series of checks
within the if-then-else statement. If the check
conditions evaluate to true, then the EndCurrentEdit is
invoked.

One of the conditions is not necessary and indeed should
be removed.

If ... <some other conditions> ... AndAlso _
' The following condition should be removed.
CType(currMgr.Current, DataRowView).IsEdit Then
currMgr.EndCurrentEdit()
End If

The condition as shown above is not always evaluated to
true even though the binded control is edited (in this
case a TextBox).

I believe my problem is solved. Thank you very much.

John Hui
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top