views:

2481

answers:

4

Visual Studio complains: Warning 1 The designer must create an instance of type 'RentalEase.CustomBindingNavForm' but it cannot because the type is declared as abstract.

Visual Studio won't let me access the Designer for the form. The class already implements all abstract methods from the CustomBindingNavForm. CustomBindingNavForm provides some functions concrete and abstract.

Is there a way around this?

Here is the class:

 public abstract class CustomBindingNavForm : SingleInstanceForm {     

        //Flags for managing BindingSource
        protected bool isNew = false;
        protected bool isUpdating = false;

        /// <summary>
        /// This is so that when a new item is added, it sets isNew and firstPass to true. The Position Changed Event will look for
        /// firstPass and if it is true set it to false. Then on the next pass, it will see it's false and set isNew to false.
        /// This is needed because the Position Changed Event will fire when a new item is added.
        /// </summary>
        protected bool firstPass = false;


        protected abstract bool validateInput();
        protected abstract void saveToDatabase();


        //manipulating binding
        protected abstract void bindingSourceCancelResetCurrent();
        protected abstract void bindingSourceRemoveCurrent();
        protected abstract void bindingSourceMoveFirst();
        protected abstract void bindingSourceMoveNext();
        protected abstract void bindingSourceMoveLast();
        protected abstract void bindingSourceMovePrevious();
        protected abstract void bindingSourceAddNew();

        public void bindingNavigatorMovePreviousItem_Click(object sender, EventArgs e) {
            if (validateInput()) {
                bindingSourceMovePrevious();
            } else {
                DialogResult cont = MessageBox.Show(null, "There are errors in your data. Click Cancel to go back and fix them, or ok to continue. If you continue, changes will not be saved.", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (cont == DialogResult.OK) {
                    if (isNew) {
                        bindingSourceRemoveCurrent();
                        isNew = false;
                    } else {
                        bindingSourceCancelResetCurrent();
                        bindingSourceMovePrevious();
                    }
                }
            }
        }

        public void bindingNavigatorAddNewItem_Click(object sender, EventArgs e) {
            if (validateInput()) {
                saveToDatabase();
                bool temp = isUpdating;
                isUpdating = true;
                bindingSourceAddNew();
                isUpdating = temp;

                isNew = true;
                firstPass = true;
            } else {
                DialogResult cont = MessageBox.Show(null, "There are errors in your data. Click Cancel to go back and fix them, or ok to continue. If you continue, changes will not be saved.", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (cont == DialogResult.OK) {

                    if (isNew) {
                        bindingSourceRemoveCurrent();
                        isNew = false;
                    } else {
                        bindingSourceCancelResetCurrent();
                    }

                    bool temp = isUpdating;
                    isUpdating = true;
                    bindingSourceAddNew();
                    isUpdating = temp;

                    isNew = true;
                    firstPass = true;
                }
            }
        }

        public void bindingNavigatorMoveFirstItem_Click(object sender, EventArgs e) {
            if (validateInput()) {
                bindingSourceMoveFirst();
            } else {
                DialogResult cont = MessageBox.Show(null, "There are errors in your data. Click Cancel to go back and fix them, or ok to continue. If you continue, changes will not be saved.", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (cont == DialogResult.OK) {
                    if (isNew) {
                        bindingSourceRemoveCurrent();
                        isNew = false;
                    } else {
                        bindingSourceCancelResetCurrent();
                    }
                    bindingSourceMoveFirst();
                }
            }
        }

        public void bindingNavigatorMoveNextItem_Click(object sender, EventArgs e) {
            if (validateInput()) {
                bindingSourceMoveNext();
            } else {
                DialogResult cont = MessageBox.Show(null, "There are errors in your data. Click Cancel to go back and fix them, or ok to continue. If you continue, changes will not be saved.", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (cont == DialogResult.OK) {
                    if (isNew) {
                        bindingSourceRemoveCurrent();
                        isNew = false;
                    } else {
                        bindingSourceCancelResetCurrent();
                    }
                    bindingSourceMoveNext();
                }
            }
        }
    }
+3  A: 

You cannot design abstract base classes.

Although there is a workaround.

Geoffrey Chetwood
I have already found that work around and it does not seem to work for 2005/2008. :(
Malfist
I see nothing in your question about it. Good questions should include what you have tried already.
Geoffrey Chetwood
Well, I just found it like a minute before you posted it. Sorry.
Malfist
Also, if you have already seen this information, then surely you shouldn't be designing an abstract class right?
Geoffrey Chetwood
Actually I should be, it's the proper OOP way of doing things and I shouldn't have to change my architecture because of an IDE's bug. I had not seen this information before I make the class though. I've never had this problem with netbeans. I'm blaming microsoft.
Malfist
@Malfist: You need serious help then.
Geoffrey Chetwood
Why do I need serious help?
Malfist
There are so many reasons, and I have so little motivation to explain them all to someone who clearly doesn't want the answers.
Geoffrey Chetwood
@Malfist. I'm putting a "beat asker with hammer" button on each one of your questions.
@belgariontheking Care to explain why?
Malfist
umm, because your questions make me want to beat you with a hammer? I thought it was a pretty simple statement.
I believe I could figure that out, care to explain (like I asked) why they make you want to beat me with a hammer? (Might want to check with a therapist by the way, they can help)
Malfist
A: 

Found the Solution

Malfist
Notice: it seems to work randomly. Sometimes VS buys it, other times it won't do anything but complain
Malfist
Would you mind posting your code? The reference doesn't appear to be detailed enough. Also, any idea if this works in VS2008? I can't seem to get it to work.
Lucas B
Actually Allen's answer is the best and it refers to a SO question that is similar. http://stackoverflow.com/questions/1620847/how-can-i-get-vs2008-winforms-designer-to-render-a-form-that-implements-an-abstra
Lucas B
+1  A: 

I haven't seen the content at urban potato (its down) but Me and Smelch came up with a solution. Form itself inherits from an abstract class, so what they dont tell you is that its only the 1st level of inheritance that can't be abstract, the 2nd on down can.

From there its simply a matter of having an empty class in the middle and wrapping an #if debug around the forms declaration and you're good to go. Just be sure to release in release mode and design in debug mode (which is very typical).

You'll get full designer support and a real abstract base class at design (debug) and build (release) time because each time it ends up using your abstract base class.

The full explanation and answer is here

Allen
A: 

This link is like answer of Malfist.

Sepidar