Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with "partial" user control problem

Posted on 2007-04-07
2
Medium Priority
?
186 Views
Last Modified: 2012-05-05
I currently have a form that has 6 group boxes labeled grpbox1, grpbox2, etc.  There are several controls in each of these groupboxes: chklst1, txtbox1, chklst2, txtbox2, etc.  I want to create a single user control class that encompasses all the functionality and design so I can replace the individual ones with an array list of the user control class.  I did this same procedure before a long time ago and was successful.  I'm having a hell of time trying to do it again.  When I add a new user control object to my solution, I get the following:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Inhallation
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }
    }
}

This is before I cut and paste anything.  What's different is this "partial" keyword appearing.  The other isolated class I made looks like this:

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace Inhallation
{
      /// <summary>
      /// Summary description for clsDisplay.
      /// </summary>
      public class clsDisplay : System.Windows.Forms.UserControl
      {
...............

What am I doing wrong?  I can't follow the same pattern to finish this new control.  Thanks!


0
Comment
Question by:jvalescu
[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
2 Comments
 
LVL 5

Accepted Solution

by:
Yttribium earned 1000 total points
ID: 18870326
Nothing as far as I'm aware, Partial classes is a feature of .NET 2.0 if I'm not mistaken.  This allows you to create a class in 2 seperate files.   e.g.

partial class ATest
      {
            public ATest()
            {
                  i = 5;
                  //contructor
            }
      }

      partial class ATest
      {
            public int i = 0;
      }

This will compile, and work as if it were like this

class ATest
      {
            public int i = 0;
            public ATest()
            {
                  i = 5;
                  //contructor
            }
      }

Hope this helps.
0
 
LVL 3

Assisted Solution

by:kingtam2000
kingtam2000 earned 1000 total points
ID: 18870329
The partial keyword is allows for classes to be split into multiple parts, so here the partial keyword allows the user control to have part of the class be in one file, which contains only the data the user adds, while there is another file, called UserControl1.Designer.cs (or whatever the UserControl is called), which contains the data that the Form Designer uses, which will contain data on the controls, etc.  To access the Designer.cs file, click the + button on the left the user control file to in the Solution Explorer, which is in the top right hand corner to expand out to get the Designer.cs file.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

661 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