ol muser
asked on
event not firing for a composite control
Hi, I have a composite control that currently only has one masked edit box. I would like to capture the value of text entered in the text box when focus leaves the composite control. I was surprised to see the Leave event available for a composite control and I was excited as that would solve my problem, but that does not fire for me. In the containing class for the composite control, a winfows form, I need to capture the value entered in the masked edit box and without that its hard for me to capture the values properly. Not sure if this would make a difference, but for the masked edit control I ahve the following events defined:
maskededit_TypeValidationC ompleted
maskededit_KeyDown
maskededit_DoubleClick
maskededit_Leave
And below is the hierarchy of my controls:
-----------
windows form
-----------
composite
-----------
maskediedit
-----------
-----------
-----------
Environment: c# using visual studio 2008
maskededit_TypeValidationC
maskededit_KeyDown
maskededit_DoubleClick
maskededit_Leave
And below is the hierarchy of my controls:
-----------
windows form
-----------
composite
-----------
maskediedit
-----------
-----------
-----------
Environment: c# using visual studio 2008
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
great help thanks! But I can see that the custom leave evetn as well as the maskededit_KeyDown event both are fired only when I press the same key (tab) twice but not the first time...any idea there?
Where was the focus before you hit the tab key twice? Where does focus move to on the first tab?
ASKER
Just in case the whole class is below. In addition I have the custom event handler in the containing form as you have recommended, but the event fires only the 2nd time I press the tab key!!!!!! thanks in advance:
namespace TxDateTimePicker
{
public partial class TxDateTimeControl : UserControl
{
private string m_DateTimeSelected;
public delegate void UserControlLeaveDelegate(TxDateTimeControl uc, string value);
public event UserControlLeaveDelegate UserControlLeave;
public TxDateTimeControl()
{
InitializeComponent();
}
private void TxDateTimeControl_Load(object sender, EventArgs e)
{
mtbDateTime.ValidatingType = typeof(System.DateTime);
mtbDateTime.TypeValidationCompleted += new TypeValidationEventHandler(mtbDateTime_TypeValidationCompleted);
}
private void mtbDateTime_TypeValidationCompleted(object sender, TypeValidationEventArgs e)
{
if (!e.IsValidInput)
{
ttErrorMsg.ToolTipTitle = "Invalid Date";
ttErrorMsg.Show("The data you supplied must be a valid date in the format mm/dd/yyyy.", mtbDateTime, 25, -60, 5000);
}
}
private void mtbDateTime_DoubleClick(object sender, EventArgs e)
{
mtbDateTime.Text = System.DateTime.Today.ToString("MM/dd/yyyy");
m_DateTimeSelected = mtbDateTime.Text;
}
private void mtbDateTime_Leave(object sender, EventArgs e)
{
//m_DateTimeSelected = mtbDateTime.Text;
if (UserControlLeave != null)
{
UserControlLeave(this, mtbDateTime.Text);
}
}
public string DateTimeSelected {
get { return m_DateTimeSelected; }
set { m_DateTimeSelected = value; mtbDateTime.Text = m_DateTimeSelected; }
}
}
}
It's working for me with only ONE tab. What else is on the form?
ASKER
On the form I have other typical windos controls. What I found is when I traverse using tab key to arricve at this control then it works fine, a single tab is sufficient to move it to the next control. But if I use a mouse click (single or double) then it requires two tabs.
For now as a work around I ahve removed the masked edit in the composite control and using a text box, to avoid this.
thanks
For now as a work around I ahve removed the masked edit in the composite control and using a text box, to avoid this.
thanks
I still can't reproduce the symptom. Even when clicking, or double clicking into the control, a single tab takes me out.
Open in new window