473,788 Members | 2,892 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# validating event problem for a super genius

I have an amazing problem which i think i have no hope of solving

Im working with a c# dot net module that is hosted by and runs under a
delphi form envrioment. Dont ask me how this insanity has prevailed
it just is :)

My problem is this

im trying to validate the contents of a textbox (it has to be a normal
textbox) and on a c# winforms and i am calling the textbox validating
event to check for bad data entry and in doing so causing the

eg test example
e.Cancel = nameTextBox.Tex t.Contains("!") ;

to be set to true, to halt focus at the textbox when bad data is
entered. On its own it works fine, but when hosted under the delphi
form application once the validating event has fired it will not
release focus away from the textbox at all

I desperatly need a way to be able to cancel the validating event so
that i can use other buttons that have become not clickable on other
parts of the winforms.

As i said it all works perfectly when run in the studio dev
enviroment, but when run as it needs to hosted by a delphi forms app
we have verified the validating events just wont seem to release focus

if anyone has any ideas or thoughts it would be appreciated

thanks

Peted
Jun 27 '08 #1
8 4128
Peted wrote:
I have an amazing problem which i think i have no hope of solving

Im working with a c# dot net module that is hosted by and runs under a
delphi form envrioment. Dont ask me how this insanity has prevailed
it just is :)

My problem is this

im trying to validate the contents of a textbox (it has to be a normal
textbox) and on a c# winforms and i am calling the textbox validating
event to check for bad data entry and in doing so causing the

eg test example
e.Cancel = nameTextBox.Tex t.Contains("!") ;

to be set to true, to halt focus at the textbox when bad data is
entered. On its own it works fine, but when hosted under the delphi
form application once the validating event has fired it will not
release focus away from the textbox at all

I desperatly need a way to be able to cancel the validating event so
that i can use other buttons that have become not clickable on other
parts of the winforms.

As i said it all works perfectly when run in the studio dev
enviroment, but when run as it needs to hosted by a delphi forms app
we have verified the validating events just wont seem to release focus

if anyone has any ideas or thoughts it would be appreciated
I would try creating the .NET controls from a separate thread which calls
Application.Run ... that way you have an event loop independent of the Delphi
one and any non-standard behavior it implements.
>
thanks

Peted

Jun 27 '08 #2
On Apr 29, 4:51*am, Peted wrote:
I have an amazing problem which i think i have no hope of solving

Im working with a c# dot net module that is hosted by and runs under a
delphi form envrioment. Dont ask me how this insanity has prevailed
it just is :)

My problem is this

im trying to validate the contents of a textbox (it has to be a normal
textbox) and on a c# winforms and i am calling the textbox validating
event to check for bad data entry and in doing so causing the

eg test example
*e.Cancel = nameTextBox.Tex t.Contains("!") ;

to be set to true, to halt focus at the textbox when bad data is
entered. On its own it works fine, but when hosted under the delphi
form application once the validating event has fired it will not
release focus away from the textbox at all

I desperatly need a way to be able to cancel the validating event so
that i can use other buttons that have become not clickable on other
parts of the winforms.

As i said it all works perfectly when run in the studio dev
enviroment, but when run as it needs to hosted by a delphi forms app
we have verified the validating events just wont seem to release focus

if anyone has any ideas or thoughts it would be appreciated

thanks

Peted
I second Ben suggestion. It's possible that the Delphi form
environment is filtering or dispatching messages differently which is
what is actually causing the problem. This is one of those rare
situations where I think having multiple message loops running is
okay. If that doesn't fix your problem then you have something deeper
than the application message pump to contend with, which seems
unlikely to me.
Jun 27 '08 #3
thanks for the advice

any chance you could point me to an example of creating .net controls
from seperate threads as you have described ?

thanks

Peted
>
I would try creating the .NET controls from a separate thread which calls
Application.Ru n... that way you have an event loop independent of the Delphi
one and any non-standard behavior it implements.

Jun 27 '08 #4
On Apr 29, 7:47*pm, Peted wrote:
thanks for the advice

any chance you could point me to an example of creating .net controls
from seperate threads as you have described ?
Start a thread like you would any other thread and then immediately
call Application.Run . It accepts a Form parameter which will
automatically be shown up execution of the method. It's no different
than code Visual Studio generates for you when you Windows Forms
application except that another thread is involved.
Jun 27 '08 #5
Brian Gideon wrote:
On Apr 29, 7:47 pm, Peted wrote:
>thanks for the advice

any chance you could point me to an example of creating .net controls
from seperate threads as you have described ?

Start a thread like you would any other thread and then immediately
call Application.Run . It accepts a Form parameter which will
automatically be shown up execution of the method. It's no different
than code Visual Studio generates for you when you Windows Forms
application except that another thread is involved.
Or if you want just a few controls, not the whole Form shown from the other
thread, you can call
new TextBox() or whatever control type
and read the Handle property to make sure it is created from the new thread,
then call the parent form's Controls.Add method, passing in the newly
created control.
Jun 27 '08 #6
On Apr 30, 1:14*pm, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
Or if you want just a few controls, not the whole Form shown from the other
thread, you can call
new TextBox() or whatever control type
and read the Handle property to make sure it is created from the new thread,
then call the parent form's Controls.Add method, passing in the newly
created control.
I hadn't thought about that before. I guess I've always been using
the assumption that this would cause chaos. How would the parent form
and the child control interact seeing as they are running on separate
threads? And from a developers perspective, writing code that
accesses the child control from the parent form would be cumbersome
and slow since everything would have to be marshaled between the
threads to maintain the thread affinity requirements right?

Jun 27 '08 #7
Brian Gideon wrote:
On Apr 30, 1:14 pm, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
>Or if you want just a few controls, not the whole Form shown from
the other thread, you can call
new TextBox() or whatever control type
and read the Handle property to make sure it is created from the new
thread, then call the parent form's Controls.Add method, passing in
the newly created control.

I hadn't thought about that before. I guess I've always been using
the assumption that this would cause chaos. How would the parent form
Plugins are often hosted on another thread (embedded video player, acrobat
reader, that sort of thing).
and the child control interact seeing as they are running on separate
threads? And from a developers perspective, writing code that
Using windows messages SendMessage(WM_ *, ...), often via a helper such as
GetWindowText or GetDlgItemText, same as they do from the same thread.
accesses the child control from the parent form would be cumbersome
and slow since everything would have to be marshaled between the
threads to maintain the thread affinity requirements right?
This "thread affinity" thing is an artificial creation of .NET.

The underlying windows calls work just fine across threads. And if your
control is hosted in a non-.NET form, then all the extra .NET baggage that
makes threading assumptions isn't present anyway.
Jun 27 '08 #8
On May 1, 8:45*am, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
Brian Gideon wrote:
On Apr 30, 1:14 pm, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
Or if you want just a few controls, not the whole Form shown from
the other thread, you can call
new TextBox() or whatever control type
and read the Handle property to make sure it is created from the new
thread, then call the parent form's Controls.Add method, passing in
the newly created control.
I hadn't thought about that before. *I guess I've always been using
the assumption that this would cause chaos. *How would the parent form

Plugins are often hosted on another thread (embedded video player, acrobat
reader, that sort of thing).
and the child control interact seeing as they are running on separate
threads? *And from a developers perspective, writing code that

Using windows messages SendMessage(WM_ *, ...), often via a helper such as
GetWindowText or GetDlgItemText, same as they do from the same thread.
accesses the child control from the parent form would be cumbersome
and slow since everything would have to be marshaled between the
threads to maintain the thread affinity requirements right?

This "thread affinity" thing is an artificial creation of .NET.

The underlying windows calls work just fine across threads. *And if your
control is hosted in a non-.NET form, then all the extra .NET baggage that
makes threading assumptions isn't present anyway.
Excellent. Ya know...I've doing this for a long time so it just goes
to show that there will always be something to learn!
Jun 27 '08 #9

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

Similar topics

6
5800
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed to leave the textbox without entering the right information. Is there a way to determine which other control was clicked in the validating event of the textbox? Thanks
0
1554
by: Joe | last post by:
Hi For a while now I have been finding postings of problems with the validating event not firing on controls properly. I too had this problem. The event would fire when clicking on another control which had it's causes validation property set to true however if I tabbed on to this control the event wouldn't fire. So after playing around with my code I figured out how to get it to work. I am not sure what the reason behind it is but it...
2
2128
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating event, I check that the string in the textbox is a file that exists or whether or not the string is blank and display a message box in either case. I also call e.Cancel so that the value will be corrected. However, certain buttons on the form...
0
2472
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls which are not behaving as I would expect. Specifically, if there is a command button external to the usercontrol which is activated by a shortcut key (eg Alt-B), the command button Click event handler code 'executes' even though the textbox set...
0
2440
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852 (http://support.microsoft.com/kb/810852), but then I realized that the hotfix mentioned was in .Net v1.1, which I am using. I took the sample from that article and recreated the situation I see in my application. (Code included below.) If you run the...
21
9220
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on the cancel button, the textbox.validating is being called. I don't want it to be since they are exiting the screen the validation doesn't have to be done. How can I do that.
6
4755
by: Ryan | last post by:
I have a windows form that I want to force validation on controls (text boxes) when the user clicks a "Save" button. The only way I've found to do this is to cycle through every control and call it's .Select() method. This is clunky though because you can see a flash in each text box as it's being validated. Here's my code Private Sub Save() For each c as control in Me.Controls If c.CanSelect() then c.Select()
16
5513
by: Al Santino | last post by:
Hi, It appears displaying a messagebox in a validating event will cancel the subsequent event. In the program below, button 2's click event doesn't fire if you open a dialog box in button 1's validating event. Am I doing something wrong here? Thanks Al Imports system
3
2799
by: TheSteph | last post by:
Hi Experts ! I have a Winform Program in C# / .NET 2.0 I would like to ensure that a value in a TextBox is a valid Int32 when user get out of it (TextBox loose focus)
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10175
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
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 we have to send another system
3
2894
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.