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_Leave(object sender, System.EventArgs e)
{
frmDealerSearch f = new frmDealerSearch();
f.ShowDialog();
}
}
public class frmDealerSearch : System.Windows.Forms.Form
{
private void cmdCancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
} 13 2293
Use DialogResult -
public class frmDataEntry : System.Windows.Forms.Form
{
private void txtDealerNum_Leave(object sender, System.EventArgs e)
{
frmDealerSearch f = new frmDealerSearch();
if (f.ShowDialog() == DialogResult.Cancel)
{
//set focus here
}
}
}
public class frmDealerSearch : System.Windows.Forms.Form
{
private void cmdCancel_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
--
Adam Clauss
"Mike L" <Ca***@nospam.nospam> wrote in message
news:21**********************************@microsof t.com... 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_Leave(object sender, System.EventArgs e) { frmDealerSearch f = new frmDealerSearch(); f.ShowDialog(); }
}
public class frmDealerSearch : System.Windows.Forms.Form { private void cmdCancel_Click(object sender, System.EventArgs e) { this.Close(); } }
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.Cancel )
{
txtDealerNum.Focus();
}
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_Leave(object sender, System.EventArgs e) { frmDealerSearch f = new frmDealerSearch(); f.ShowDialog(); }
}
public class frmDealerSearch : System.Windows.Forms.Form { private void cmdCancel_Click(object sender, System.EventArgs e) { this.Close(); } }
Doesn't work, f.ShowDialog() comes back as <overload> and DialogResult.Cancel
comes back as None.
"Adam Clauss" wrote: Use DialogResult -
public class frmDataEntry : System.Windows.Forms.Form { private void txtDealerNum_Leave(object sender, System.EventArgs e) { frmDealerSearch f = new frmDealerSearch(); if (f.ShowDialog() == DialogResult.Cancel) { //set focus here } }
}
public class frmDealerSearch : System.Windows.Forms.Form { private void cmdCancel_Click(object sender, System.EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } }
-- Adam Clauss
"Mike L" <Ca***@nospam.nospam> wrote in message news:21**********************************@microsof t.com...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_Leave(object sender, System.EventArgs e) { frmDealerSearch f = new frmDealerSearch(); f.ShowDialog(); }
}
public class frmDealerSearch : System.Windows.Forms.Form { private void cmdCancel_Click(object sender, System.EventArgs e) { this.Close(); } }
Doesn't work, f.ShowDialog() comes back as <overload> and DialogResult.Cancel
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.Cancel ) { txtDealerNum.Focus(); }
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_Leave(object sender, System.EventArgs e) { frmDealerSearch f = new frmDealerSearch(); f.ShowDialog(); }
}
public class frmDealerSearch : System.Windows.Forms.Form { private void cmdCancel_Click(object sender, System.EventArgs e) { this.Close(); } }
"Mike L" <Ca***@nospam.nospam> wrote in message
news:58**********************************@microsof t.com... Doesn't work, f.ShowDialog() comes back as <overload> and DialogResult.Cancel 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
Make sure that you have the DialogResult property of your cancel button set
to "Cancel".
"Mike L" <Ca***@nospam.nospam> wrote in message
news:B3**********************************@microsof t.com... Doesn't work, f.ShowDialog() comes back as <overload> and DialogResult.Cancel 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.Cancel ) { txtDealerNum.Focus(); }
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_Leave(object sender, System.EventArgs e) > { > frmDealerSearch f = new > frmDealerSearch(); > f.ShowDialog(); > } > > } > > > public class frmDealerSearch : System.Windows.Forms.Form > { > private void cmdCancel_Click(object sender, System.EventArgs e) > { > this.Close(); > } > } >
I did have the DialogResult property of my cancel button set to "Cancel".
Here is the code.
namespace LicenseDealerSales
{
/// <summary>
/// Summary description for frmDataEntry.
/// </summary>
public class frmDataEntry : System.Windows.Forms.Form
{
private void txtDealerNum_Leave(object sender,
System.EventArgs e)
{
if (txtDealerNum.Text.Length != 6)
{
MessageBox.Show("Dealer Number requires 6
digits.", "Invaild Data",MessageBoxButtons.OK);
txtDealerNum.Focus();
}
else
{
frmDealerSearch f = new frmDealerSearch();
if( f.ShowDialog() == DialogResult.Cancel )
{
txtDealerNum.Focus();
}
}
}
}
}
namespace LicenseDealerSales
{
/// <summary>
/// Summary description for frmDealerSearch.
/// </summary>
public class frmDealerSearch : System.Windows.Forms.Form
{
private void cmdCancel_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
}
}
"Adam Clauss" wrote: "Mike L" <Ca***@nospam.nospam> wrote in message news:58**********************************@microsof t.com... Doesn't work, f.ShowDialog() comes back as <overload> and DialogResult.Cancel 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
I did have the DialogResult property of my cancel button set to "Cancel".
Here is the code.
namespace LicenseDealerSales
{
/// <summary>
/// Summary description for frmDataEntry.
/// </summary>
public class frmDataEntry : System.Windows.Forms.Form
{
private void txtDealerNum_Leave(object sender,
System.EventArgs e)
{
if (txtDealerNum.Text.Length != 6)
{
MessageBox.Show("Dealer Number requires 6
digits.", "Invaild Data",MessageBoxButtons.OK);
txtDealerNum.Focus();
}
else
{
frmDealerSearch f = new frmDealerSearch();
if( f.ShowDialog() == DialogResult.Cancel )
{
txtDealerNum.Focus();
}
}
}
}
}
namespace LicenseDealerSales
{
/// <summary>
/// Summary description for frmDealerSearch.
/// </summary>
public class frmDealerSearch : System.Windows.Forms.Form
{
private void cmdCancel_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
}
}
"Phil S" wrote: Make sure that you have the DialogResult property of your cancel button set to "Cancel".
"Mike L" <Ca***@nospam.nospam> wrote in message news:B3**********************************@microsof t.com... Doesn't work, f.ShowDialog() comes back as <overload> and DialogResult.Cancel 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.Cancel ) { txtDealerNum.Focus(); }
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_Leave(object sender, System.EventArgs e) > { > frmDealerSearch f = new > frmDealerSearch(); > f.ShowDialog(); > } > > } > > > public class frmDealerSearch : System.Windows.Forms.Form > { > private void cmdCancel_Click(object sender, System.EventArgs e) > { > this.Close(); > } > } >
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.Focus(); to see if dialog result is Cancel.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
The Cancel button works but the OK button fires off another form, then the
program crashes.
"Kevin Yu [MSFT]" wrote: 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.Focus(); to see if dialog result is Cancel.
Kevin Yu ======= "This posting is provided "AS IS" with no warranties, and confers no rights."
I figured it out. I had to add the code this.DialogResult = DialogResult.OK;
to the OK button.
"Mike L" wrote: I did have the DialogResult property of my cancel button set to "Cancel".
Here is the code.
namespace LicenseDealerSales { /// <summary> /// Summary description for frmDataEntry. /// </summary> public class frmDataEntry : System.Windows.Forms.Form { private void txtDealerNum_Leave(object sender, System.EventArgs e) { if (txtDealerNum.Text.Length != 6) { MessageBox.Show("Dealer Number requires 6 digits.", "Invaild Data",MessageBoxButtons.OK); txtDealerNum.Focus(); } else {
frmDealerSearch f = new frmDealerSearch(); if( f.ShowDialog() == DialogResult.Cancel ) { txtDealerNum.Focus(); } } } } }
namespace LicenseDealerSales { /// <summary> /// Summary description for frmDealerSearch. /// </summary> public class frmDealerSearch : System.Windows.Forms.Form { private void cmdCancel_Click(object sender, System.EventArgs e) { this.DialogResult = DialogResult.Cancel;
} } }
"Phil S" wrote:
Make sure that you have the DialogResult property of your cancel button set to "Cancel".
"Mike L" <Ca***@nospam.nospam> wrote in message news:B3**********************************@microsof t.com... Doesn't work, f.ShowDialog() comes back as <overload> and DialogResult.Cancel 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.Cancel ) > { > txtDealerNum.Focus(); > } > > 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_Leave(object sender, System.EventArgs e) > > { > > frmDealerSearch f = new > > frmDealerSearch(); > > f.ShowDialog(); > > } > > > > } > > > > > > public class frmDealerSearch : System.Windows.Forms.Form > > { > > private void cmdCancel_Click(object sender, System.EventArgs e) > > { > > this.Close(); > > } > > } > >
I figured it out. I had to add the code this.DialogResult = DialogResult.OK;
to the OK button.
"Mike L" wrote: The Cancel button works but the OK button fires off another form, then the program crashes.
"Kevin Yu [MSFT]" wrote:
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.Focus(); to see if dialog result is Cancel.
Kevin Yu ======= "This posting is provided "AS IS" with no warranties, and confers no rights."
Nice to hear that you have got the issue resolved.
Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights." This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |