Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have an event deleclared for text box not to allow any special characters,if we place any textbox in the child forms.but there is one case where I have not to check for the base class event .how can i overide the base class event in the child class so that the form should not take the base class event for the specified text box

following is the sample code
in base form i have

public static void SetCustomDisabled{
textbox.ParseEditValue += new ConvertEditValueEventHandler(ParseEditValue)
}

Private void memo_ParseEditValue(object sender,
.ConvertEditValueEventArgs e)
{
e.Value = false;


}

Thanks in advance
Posted
Comments
Maarten Kools 5-Aug-13 9:53am    
Just make the ParseEditValue method virtual and override it in your derived class. Is that what you mean?

try this
C#
Private void memo_ParseEditValue(object sender, 
.ConvertEditValueEventArgs e)
{
if (sender.ToString().Contains("textbox1"))//your control name which you dont want to handle
            {

            }
            else
            {
                e.Value = false;            
            }
 

}
 
Share this answer
 
Comments
lakshmichawala 5-Aug-13 10:13am    
hi Basmeh Awad i want to overide the event in the child class how can i write overide method so that it should not take the base class event
Just attach the event you want to do the work, I am confused by the override comment as you are not overriding anything, you are attaching an event. Just attach a different method to handle the event for the 'special' text box.

Create an additional method, along with your original, to handle the special text box's event, like so...
C#
Private void memo_ParseEditValue(object sender,ConvertEditValueEventArgs e)
{
    // do something to original text box
    e.Value = false;
}

Private void memo_SpecialParseEditValue(object sender,ConvertEditValueEventArgs e)
{
    // do something different for the special text box
}


Then attach the new method to handle the special text box, like so...
C#
public static void SetCustomDisabled
{
    // attach to original text box
    textbox.ParseEditValue += new ConvertEditValueEventHandler(memo_ParseEditValue)

    // attach different method to the special text box
    textboxSpecial.ParseEditValue += new SpecialConvertEditValueEventHandler(memo_SpecialParseEditValue)
}
 
Share this answer
 
v3
Comments
lakshmichawala 5-Aug-13 13:21pm    
Hi Thanks a lot ...The problem in my application is that in the base form in of the public virtual void disablecontrol method There is a foreach loop of each control and if the control is of text box then they are calling the parsedit value event and attaching the memo_parseeditvalue method.so in the child form when iam using any textbox it is taking the base form defined event and unable to change the some values in the textbox which I defined .so how can I overide this event in the Child form
idenizeni 5-Aug-13 15:00pm    
To clarify my understanding...
You have a form (let's call it Form1) with textbox controls and in Form1 you are attaching events to the textboxes. Now you also have a form that inherits from Form1 (let's call it Form1Child) and Form1Child is where you want to override the method and you want to override it for all textboxes in Form1Child, is this correct?

Also, why is SetCustomDisabled a static method? Would it solve your problem if you removed the static indicator and made this method overridable? If so you could override the SetCustomDisabled function in your child form.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900