473,732 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Focus on field if Cancel on child form

I have a child form frmDataEntry call up another child form frmDealerSearch .
If the user clicks on cancel on frmDealerSearch , I want to close
frmDealerSearch and put the focus on txtDealerNum on frmDataEntry.

Here is my code.

public class frmDataEntry : System.Windows. Forms.Form
{
private void txtDealerNum_Le ave(object sender, System.EventArg s e)
{
frmDealerSearch f = new frmDealerSearch ();
f.ShowDialog();
}

}
public class frmDealerSearch : System.Windows. Forms.Form
{
private void cmdCancel_Click (object sender, System.EventArg s e)
{
this.Close();
}
}

Nov 17 '05 #1
13 2320
Use DialogResult -

public class frmDataEntry : System.Windows. Forms.Form
{
private void txtDealerNum_Le ave(object sender, System.EventArg s e)
{
frmDealerSearch f = new frmDealerSearch ();
if (f.ShowDialog() == DialogResult.Ca ncel)
{
//set focus here
}
}

}
public class frmDealerSearch : System.Windows. Forms.Form
{
private void cmdCancel_Click (object sender, System.EventArg s e)
{
this.DialogResu lt = DialogResult.Ca ncel;
this.Close();
}
}
--
Adam Clauss

"Mike L" <Ca***@nospam.n ospam> wrote in message
news:21******** *************** ***********@mic rosoft.com...
I have a child form frmDataEntry call up another child form
frmDealerSearc h.
If the user clicks on cancel on frmDealerSearch , I want to close
frmDealerSearch and put the focus on txtDealerNum on frmDataEntry.

Here is my code.

public class frmDataEntry : System.Windows. Forms.Form
{
private void txtDealerNum_Le ave(object sender, System.EventArg s e)
{
frmDealerSearch f = new frmDealerSearch ();
f.ShowDialog();
}

}
public class frmDealerSearch : System.Windows. Forms.Form
{
private void cmdCancel_Click (object sender, System.EventArg s e)
{
this.Close();
}
}

Nov 17 '05 #2
On frmDealerSearch , make sure that the CancelButton property is set to the
forms Cancel Button. In addition, set the DialogResult property of this
button to Cancel. Also, you remove the this.Close() from cmdCancel_Click as
it will occur automatically.

Next, you’d want to be aware of the return value from f.ShowDialog(), and
based on it act to set the focus to txtDealerNum, much like:

if( f.ShowDialog() == DialogResult.Ca ncel )
{
txtDealerNum.Fo cus();
}

Brendan
"Mike L" wrote:
I have a child form frmDataEntry call up another child form frmDealerSearch .
If the user clicks on cancel on frmDealerSearch , I want to close
frmDealerSearch and put the focus on txtDealerNum on frmDataEntry.

Here is my code.

public class frmDataEntry : System.Windows. Forms.Form
{
private void txtDealerNum_Le ave(object sender, System.EventArg s e)
{
frmDealerSearch f = new frmDealerSearch ();
f.ShowDialog();
}

}
public class frmDealerSearch : System.Windows. Forms.Form
{
private void cmdCancel_Click (object sender, System.EventArg s e)
{
this.Close();
}
}

Nov 17 '05 #3
Doesn't work, f.ShowDialog() comes back as <overload> and DialogResult.Ca ncel
comes back as None.

"Adam Clauss" wrote:
Use DialogResult -

public class frmDataEntry : System.Windows. Forms.Form
{
private void txtDealerNum_Le ave(object sender, System.EventArg s e)
{
frmDealerSearch f = new frmDealerSearch ();
if (f.ShowDialog() == DialogResult.Ca ncel)
{
//set focus here
}
}

}
public class frmDealerSearch : System.Windows. Forms.Form
{
private void cmdCancel_Click (object sender, System.EventArg s e)
{
this.DialogResu lt = DialogResult.Ca ncel;
this.Close();
}
}
--
Adam Clauss

"Mike L" <Ca***@nospam.n ospam> wrote in message
news:21******** *************** ***********@mic rosoft.com...
I have a child form frmDataEntry call up another child form
frmDealerSearc h.
If the user clicks on cancel on frmDealerSearch , I want to close
frmDealerSearch and put the focus on txtDealerNum on frmDataEntry.

Here is my code.

public class frmDataEntry : System.Windows. Forms.Form
{
private void txtDealerNum_Le ave(object sender, System.EventArg s e)
{
frmDealerSearch f = new frmDealerSearch ();
f.ShowDialog();
}

}
public class frmDealerSearch : System.Windows. Forms.Form
{
private void cmdCancel_Click (object sender, System.EventArg s e)
{
this.Close();
}
}


Nov 17 '05 #4
Doesn't work, f.ShowDialog() comes back as <overload> and DialogResult.Ca ncel
comes back as None.

"Brendan Grant" wrote:
On frmDealerSearch , make sure that the CancelButton property is set to the
forms Cancel Button. In addition, set the DialogResult property of this
button to Cancel. Also, you remove the this.Close() from cmdCancel_Click as
it will occur automatically.

Next, you’d want to be aware of the return value from f.ShowDialog(), and
based on it act to set the focus to txtDealerNum, much like:

if( f.ShowDialog() == DialogResult.Ca ncel )
{
txtDealerNum.Fo cus();
}

Brendan
"Mike L" wrote:
I have a child form frmDataEntry call up another child form frmDealerSearch .
If the user clicks on cancel on frmDealerSearch , I want to close
frmDealerSearch and put the focus on txtDealerNum on frmDataEntry.

Here is my code.

public class frmDataEntry : System.Windows. Forms.Form
{
private void txtDealerNum_Le ave(object sender, System.EventArg s e)
{
frmDealerSearch f = new frmDealerSearch ();
f.ShowDialog();
}

}
public class frmDealerSearch : System.Windows. Forms.Form
{
private void cmdCancel_Click (object sender, System.EventArg s e)
{
this.Close();
}
}

Nov 17 '05 #5
"Mike L" <Ca***@nospam.n ospam> wrote in message
news:58******** *************** ***********@mic rosoft.com...
Doesn't work, f.ShowDialog() comes back as <overload> and
DialogResult.Ca ncel
comes back as None.


I'm not sure exactly what you mean by that.
Show the code you are using now, just so we can make it is what we intended.

--
Adam Clauss

Nov 17 '05 #6
Make sure that you have the DialogResult property of your cancel button set
to "Cancel".
"Mike L" <Ca***@nospam.n ospam> wrote in message
news:B3******** *************** ***********@mic rosoft.com...
Doesn't work, f.ShowDialog() comes back as <overload> and
DialogResult.Ca ncel
comes back as None.

"Brendan Grant" wrote:
On frmDealerSearch , make sure that the CancelButton property is set to
the
forms Cancel Button. In addition, set the DialogResult property of this
button to Cancel. Also, you remove the this.Close() from cmdCancel_Click
as
it will occur automatically.

Next, you'd want to be aware of the return value from f.ShowDialog(), and
based on it act to set the focus to txtDealerNum, much like:

if( f.ShowDialog() == DialogResult.Ca ncel )
{
txtDealerNum.Fo cus();
}

Brendan
"Mike L" wrote:
> I have a child form frmDataEntry call up another child form
> frmDealerSearch .
> If the user clicks on cancel on frmDealerSearch , I want to close
> frmDealerSearch and put the focus on txtDealerNum on frmDataEntry.
>
> Here is my code.
>
> public class frmDataEntry : System.Windows. Forms.Form
> {
> private void txtDealerNum_Le ave(object sender, System.EventArg s e)
> {
> frmDealerSearch f = new
> frmDealerSearch ();
> f.ShowDialog();
> }
>
> }
>
>
> public class frmDealerSearch : System.Windows. Forms.Form
> {
> private void cmdCancel_Click (object sender, System.EventArg s e)
> {
> this.Close();
> }
> }
>

Nov 17 '05 #7
I did have the DialogResult property of my cancel button set to "Cancel".

Here is the code.

namespace LicenseDealerSa les
{
/// <summary>
/// Summary description for frmDataEntry.
/// </summary>
public class frmDataEntry : System.Windows. Forms.Form
{
private void txtDealerNum_Le ave(object sender,
System.EventArg s e)
{
if (txtDealerNum.T ext.Length != 6)
{
MessageBox.Show ("Dealer Number requires 6
digits.", "Invaild Data",MessageBo xButtons.OK);
txtDealerNum.Fo cus();
}
else
{

frmDealerSearch f = new frmDealerSearch ();
if( f.ShowDialog() == DialogResult.Ca ncel )
{
txtDealerNum.Fo cus();
}
}
}
}
}
namespace LicenseDealerSa les
{
/// <summary>
/// Summary description for frmDealerSearch .
/// </summary>
public class frmDealerSearch : System.Windows. Forms.Form
{
private void cmdCancel_Click (object sender, System.EventArg s e)
{
this.DialogResu lt = DialogResult.Ca ncel;

}
}
}
"Adam Clauss" wrote:
"Mike L" <Ca***@nospam.n ospam> wrote in message
news:58******** *************** ***********@mic rosoft.com...
Doesn't work, f.ShowDialog() comes back as <overload> and
DialogResult.Ca ncel
comes back as None.


I'm not sure exactly what you mean by that.
Show the code you are using now, just so we can make it is what we intended.

--
Adam Clauss

Nov 17 '05 #8
I did have the DialogResult property of my cancel button set to "Cancel".

Here is the code.

namespace LicenseDealerSa les
{
/// <summary>
/// Summary description for frmDataEntry.
/// </summary>
public class frmDataEntry : System.Windows. Forms.Form
{
private void txtDealerNum_Le ave(object sender,
System.EventArg s e)
{
if (txtDealerNum.T ext.Length != 6)
{
MessageBox.Show ("Dealer Number requires 6
digits.", "Invaild Data",MessageBo xButtons.OK);
txtDealerNum.Fo cus();
}
else
{

frmDealerSearch f = new frmDealerSearch ();
if( f.ShowDialog() == DialogResult.Ca ncel )
{
txtDealerNum.Fo cus();
}
}
}
}
}
namespace LicenseDealerSa les
{
/// <summary>
/// Summary description for frmDealerSearch .
/// </summary>
public class frmDealerSearch : System.Windows. Forms.Form
{
private void cmdCancel_Click (object sender, System.EventArg s e)
{
this.DialogResu lt = DialogResult.Ca ncel;

}
}
}
"Phil S" wrote:
Make sure that you have the DialogResult property of your cancel button set
to "Cancel".
"Mike L" <Ca***@nospam.n ospam> wrote in message
news:B3******** *************** ***********@mic rosoft.com...
Doesn't work, f.ShowDialog() comes back as <overload> and
DialogResult.Ca ncel
comes back as None.

"Brendan Grant" wrote:
On frmDealerSearch , make sure that the CancelButton property is set to
the
forms Cancel Button. In addition, set the DialogResult property of this
button to Cancel. Also, you remove the this.Close() from cmdCancel_Click
as
it will occur automatically.

Next, you'd want to be aware of the return value from f.ShowDialog(), and
based on it act to set the focus to txtDealerNum, much like:

if( f.ShowDialog() == DialogResult.Ca ncel )
{
txtDealerNum.Fo cus();
}

Brendan
"Mike L" wrote:

> I have a child form frmDataEntry call up another child form
> frmDealerSearch .
> If the user clicks on cancel on frmDealerSearch , I want to close
> frmDealerSearch and put the focus on txtDealerNum on frmDataEntry.
>
> Here is my code.
>
> public class frmDataEntry : System.Windows. Forms.Form
> {
> private void txtDealerNum_Le ave(object sender, System.EventArg s e)
> {
> frmDealerSearch f = new
> frmDealerSearch ();
> f.ShowDialog();
> }
>
> }
>
>
> public class frmDealerSearch : System.Windows. Forms.Form
> {
> private void cmdCancel_Click (object sender, System.EventArg s e)
> {
> this.Close();
> }
> }
>


Nov 17 '05 #9
Hi,

I tried your code on my machine and it works fine. Can you put these code
into a new project to see if it works? Also you can put a breakpoint on
line txtDealerNum.Fo cus(); to see if dialog result is Cancel.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #10

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

Similar topics

5
19325
by: Martin | last post by:
I have the following function in the onchange event of several text boxes. If the user enters an invalid number the alert displays. I would like to return the user to that same field after he closes the alert but setting the focus as I'm doing here doesn't do it (instead, the focus goes to the next field). Any suggestions as to hwo I can make this work? Thanks.
5
5632
by: Dave Brydon | last post by:
I'm checking for required fields, and using the code below, which I normally have no difficulties with; however, as a twist I decided to return the focus back to the specific field(s) in question for input. Under the "Case vbYes" I indicated the two required fields to return the focus, based on which one is empty, however, I cannot seem to return the focus. If I only have one field indicated in the code, example; If Me.txtUDateStart =...
2
3828
by: Geir Baardsen | last post by:
Hi! This is a problem I have: I have an Orderform and an OrderDetails form. I will have the user register a sparepartnr in the OrderDetails form, but only if that number doesn't exist already. If it exist I'll have a messagebox popUp and when he clicks ok I'll set the focus on the actual field in the OrderDetails form, which is the fifth field on the line. But where do I go wrong? It all works fine, except that I can't seem to set the...
1
3368
by: tdmailbox | last post by:
Is there a vb command that can tell me if I have focus in the child or parent form? Basicly I have a search macro that needs me to have focus to any field in the parent form. If my focus is set on any field in the parent form it will search that field. However if I have focus set to a field in the child form it fails. What I want to do is set focus to field1 of the parent table but ONLY if focus is on a field in the child form. Is...
2
1845
by: Elsa Luiz | last post by:
Hi everyone, I have this problem hope you could help me... I have an A.aspx page with a button, when I click the button I would like to open another window with containing B.aspx. The problem is that the window B.aspx appears fine but the focus returns to the parent (A.aspx), I would like the focus in B.aspx window. When I click the button on A.aspx I execute the following code: private void btMyButton_Click(object sender,...
3
2774
by: Charles Law | last post by:
Under what circumstances would e.Cancel be set to True on entry to the Closing event of an MDI child form? I have found that this is why my application won't close properly. I can explicitly set the value to False, but I would have expected it to be False on entry. TIA Charles
9
6451
by: Mary | last post by:
I have a tabbed form. Tab 1 has fields that are mandatory. I am trying to validate that these fields are not null, and cancel updating if any of them are. The following code works, except the form closes instead of setting focus to the null field. What am I doing wrong? Do I need to refer to the tab name when I set focus? I sure would appreciate any help! Here is my code: Private Sub Form_BeforeUpdate(Cancel As Integer)
3
3124
by: Miro | last post by:
VB 2005 Express. I have an MDI app, and I have a child form loading in the Parent form. On the Child form I have a command button "Close". Upon click of that close, If MessageBox.Show("Are you sure you want to cancel?", _ "Cancel", _ MessageBoxButtons.YesNo, _ MessageBoxIcon.Question, _
1
2296
by: Sudarhan | last post by:
Hello frnds I have created a webbased form using asp and javascript .. while submitting the form i am validating the fields in the form .it validates the field and returns alert message. but when user clicks on alert box it submits the form instead of focusing to desired field... I have cascade style webform .so if havent filled field in 2nd sheet and i click on submit button in 4 sheet.. it prompts the alert box but does not focus to 2nd...
0
8946
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
8774
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
9447
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9235
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
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...
1
6735
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
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();...
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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.