• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

Creating classes with non-visual components

Hi,

Is there any easy way of creating classes and "dropping" non-visual components (especially dataadapters, datasets etc) within this class.

I am aware we can hand-code these within the class but this is supposed to be object (component) based RAD - isnt it?

Thanks.

James.
0
JAMES
Asked:
JAMES
  • 4
  • 4
1 Solution
 
123654789987Commented:
If u can create a Form and then click ToolBox. Right click on Toolbox and then select "All tabs" . u have a option there data. Under that u will find DataAdapter and Datasets. U select one of them and drop them on to the form. This will create a an instance of them.
0
 
JAMESAuthor Commented:
Hmmm thanks but...

Perhaps I didnt explain the question properly.  We already use the Dataadapters etc in many places but it doesnt seem possible when you are creating a class as it will only allow a text view and the component tabs (including the non-visual ones) are then not available to the developer!

James.
0
 
msdixonCommented:
you need to create a "Component Class" not a class. This adds the necessary code in the "Windows Generated Code" (or something like that) region. it consists of an Initialize method, and a way to dispose of the objects.

in your project, hit Ctrl + Shift + A to add a new item (or if you're a mouse slave, click File | Add New Item), select "Component Class". Type your file name and hit enter.

add your code, and drag & drop components on it.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
JAMESAuthor Commented:
msdixon,

Isnt the component class a framework for generating "new" components ?
0
 
msdixonCommented:
yes it is. to modify your existing class you'll have to take a look at the new class generated with the wizard and add the appropriate code. i don't remember off the top of my head what it is.
0
 
JAMESAuthor Commented:
Am I right in saying this is a "work around"?

Will check and report back - thanks so far...
0
 
msdixonCommented:
"Give a man a fish, and feed him for a day. Teach a man to fish and feed him for a lifetime"

here's your fish:

;-)

// remember to replace "[myClass]" with the actual class name
// class declaration
// inherit from Component
      public class [myClass] : System.ComponentModel.Component


// modify your constructor
            public [myClass](System.ComponentModel.IContainer container)
            {
                  ///
                  /// Required for Windows.Forms Class Composition Designer support
                  ///
                  container.Add(this);
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            public [myClass]()
            {
                  ///
                  /// Required for Windows.Forms Class Composition Designer support
                  ///
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

// add this code to your class

      #region windows stuff...

      /// <summary>
      /// Required designer variable.
      /// </summary>
      private System.ComponentModel.Container components = null;

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if(components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }


            #region Component Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  components = new System.ComponentModel.Container();
            }
            #endregion

      #endregion
0
 
JAMESAuthor Commented:
Thanks.

Fisherman James.
0
 
msdixonCommented:
glad you thought it was funny... and glad i could help.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now