Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newbie maintenance form question
Message
 
To
23/01/2004 15:02:28
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00869763
Message ID:
00870815
Views:
10
Chuck,

>What I want to have is for the box to be disabled when they are editing an existing record and enabled when they are adding a new record (i.e. right after pressing the New button.. I thank I just need to know how to hook into the button click event, but when I made a btnNew_click event, I got an error telling me "btnNew_Click shadows an overridable method in a base class." and an error telling me it needed a withEvents clause..

You're on the right track here...the reason you're getting the compiler error is because the parent (base) maintenance form has a method called btnNew_Click that is inherited by your subclass. It's marked as protected in the base class so it can be overridden if needed. Overriding this method is easier to do in C# than in VB .NET. What I recommend in this case is to create a new handler method. Here's the steps you can take (replace the "txtOrderID" reference with the name of your textbox control):

1. Set the textbox's ReadOnly property to True at design time

2. Set the textbox's AutoSetEnabled property False at design time

3. Add a new handler method to your form that sets your textbox's ReadOnly property to False. For example:
Private Sub btnNew_Click2(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Me.txtOrderID.ReadOnly = False
End Sub
4. Add the following code to your form's constructor, AFTER the call to InitializeComponent. This code registers the handler method with the New buttons' Click event:
AddHandler btnNew.Click, AddressOf btnNew_Click2
5. Double-click your form's Save button to create a new event handler (or to edit an existing one)...this works "as is" since there is no handler method in the form's base class. Add code to the method that sets the control's ReadOnly property to True. In the following example, the code checks the button's Result property to make sure the Save was successful (it also sets focus to the tab control's List page):
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    ' Activate the List page
    If Me.btnSave.Result = mmSaveDataResult.RulesPassed Then
        Me.TabControl.SelectedTab = Me.ListPage
        Me.txtOrderID.ReadOnly = True
    End If
End Sub
6. Double-click your form's Cancel button to create a new event handler (or to edit an existing one). Add code to the method that sets the contorl's ReadOnly property to True (again, this code also sets focus to the tab control's List page):
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
    Me.TabControl.SelectedTab = Me.ListPage
    Me.txtOrderID.ReadOnly = True
End Sub
Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Previous
Reply
Map
View

Click here to load this message in the networking platform