Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Component Class

Posted on 2013-10-30
3
Medium Priority
?
201 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
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

963 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