Click here to Skip to main content
14,880,436 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all - I have a problem with implementing interfaces in a C# project.

I have a Windows form with the following interface in it:

public interface Trigger
           void UpdateClient();
           void UpdateHotel();

class UpdateParties: Trigger

           static void Main()
               UpdateParties iImp = new UpdateParties();

           public void UpdateClient ()
               this.toolStripStatusLabelGuestID.Text = "Client ID: " + globals.CurrentGuestID;

               // Populate name details box
               this.tbGuest.Text = globals.PreFill;

           public void UpdateHotel ()
               this.toolStripStatusLabelHotelID.Text = "Hotel ID: " + globals.CurrentHotelID;

               // Populate name details box
               this.tbHotel.Text = globals.PreFill;


where GetHotelData() is used elsewhere by a button click event on the form itself.

Now I'm facing two problems when I try and compile this. The first is an error message along the lines of 'Myproject.frmDisplay.UpdateParties' does not contain a definition for 'toolStripStatusLabelGuestID' and no extension method 'toolStripStatusLabelGuestID' accepting a first argument of type 'Myproject.frmDisplay.UpdateParties' could be found (are you missing a using directive or an assembly reference?)

- this pops up every time I reference a control on the form itelf (toolStripStatusLabelHotelID is a label on the toolstrip bar, same thing happens for a textbox called tbGuest) and so I get four error messages of this kind.

The second error is The name 'GetHotelData' does not exist in the current context when it comes to invoking GetHotelData(). I don't want to duplicate GetHotelData() as it plays with data tables etc. on the main form and I can't shuffle those around.

How do I resolve these issues? I have other code in the form itself that invokes GetHotelData() and manipulates the controls just fine, and I don't want to start breaking things. All I need to do is invoke these methods from another form so that this form updates its display.

1 solution

No, you do not have such a Windows Form!
Start over again - create a new Windows Forms project in Visual Studio, rename Form1 to UpdateParties, add the UI elements.
And then change
public partial class UpdateParties : Form
public partial class UpdateParties : Form, Trigger
and insert the two functions from your snippet above, and the GetHotelData function.
boogac 8-Feb-13 4:41am
can you explain how do you understand that he does not have a Windows Form ? Because of 'Myproject.frmDisplay.UpdateParties' does not contain a definition for 'toolStripStatusLabelGuestID' error ??
Bernhard Hiller 8-Feb-13 10:41am
Just look at the definition:
class UpdateParties: Trigger
and "Trigger" is just his interface. No Form with that name (maybe it is somewhere else).

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