Solved

Help with "partial" user control problem

Posted on 2007-04-07
2
182 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 250 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 250 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ado.net AddWithValue when using IN condition 7 45
linq, c# 8 52
Connect Gridview column to Textbox in C# 2 55
Need a quick overview of Selenium testing 2 36
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…

752 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