Solved

Component Class

Posted on 2013-10-30
3
197 Views
Last Modified: 2013-10-31
Hi, I Just need to know the modifications needed in the following  code so that I can make this a "component " in order to drag and drop on a form.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BLLGeneric
{
    public class ValidateTitleClass
    {
        private static readonly ErrorProvider ErrorProvider = new ErrorProvider();

        public static void Validate(Control parent)
        {
            foreach (Control subcontrol in parent.Controls)
            {
                if (subcontrol is TextBox)
                {
                    var textbox = (TextBox) subcontrol;
                    var controltext = subcontrol.Name;
                    if (controltext == "Tbxdescription")
                    {
                        if (string.IsNullOrEmpty(textbox.Text))
                        {
                            ErrorProvider.SetError(subcontrol, "Field cannot be empty");
                        }
                    }
                    textbox.Text = null;
                }

                if (subcontrol.HasChildren)
                {
                    Validate(subcontrol);
                }
            }
        }

        public static object ClearErrorProvider()
        {
            ErrorProvider.Clear();
            ErrorProvider.Dispose();
            return null;
        }
    }
}

Open in new window

0
Comment
Question by:GRChandrashekar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 39613026
Are you looking for this to be an Extender Provider?

Extender Providers
http://msdn.microsoft.com/en-us/library/ms171835(v=vs.110).aspx
0
 

Author Comment

by:GRChandrashekar
ID: 39613366
No I just want to change the code I have written to a component class not sure how can i do that
0
 
LVL 40
ID: 39613521
Inherit from Component in your class declaration:

public class ValidateTitleClass:System.ComponentModel.Component

Compile and the component will appear at the top of the Toolbox.

However, I do not see why you would make a component for a class that has only static methods. You gain nothing by doing so, since the methods in the class can be called at anytime in the application.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question