Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question on instantiation

Status
Not open for further replies.

keyser456

IS-IT--Management
Nov 21, 2003
73
US
Ok, I guess I'm just not understanding this concept. I have a custom combo box I'm working with. In my custom combo box class I simply inherited System.Windows.Forms.Combobox and added one private field of type SqlCommand and added a corresponding public property. What I want to happen is when you drop the custom combo box on the form I want the SqlCommand to be instantiated so that when I select the combobox in the designer I can edit the SqlCommand items such as setting the Connection to the Connection listed on the form. As of right now, it doesn't show any connections in the drop down list of connections (using the SqlCommand) even though the form contains a connection. What am I doing wrong?
 
I think you've got the terms wrong.

Instantiation is the allocation of memory and the creation of an object to occupy that memory. If you look in the hidden area of your form's code after dropping your custom control on it, you'll see something like:
Code:
   KeysersCombo1 = New KeysersCombo();
This is the line that instantiates your control.

I think what you're asking is how to populate the SqlCommand object in your custom control at the time it is sited on your form. I'm not a custom control expert, but I have a book on it at home and I can look it up there. Pretty sure there is an event that gets raised when the control is dropped on a form, that will allow you to use the Parent property to inspect the containing control for a SqlCommand (via reflection).

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
I guess I used the word instantiation because I figured the problem is somewhere in the fact that the SqlCommand that I am instantiating in the constructor of the combo box doesn't want to talk to my form:

class MyCustomComboBox : System.Windows.Forms.ComboBox
{
private SqlCommand mySqlCmd;

//constructor
public MyCustomComboBox()
{
this.mySqlCmd = new SqlCommand();
}

//Implementation

//property
public SqlCommand MySqlCmd
{get{return this.mySqlCmd;}
set{this.mySqlCmd = value;}}
}

Now when I drop the combobox on my form and select the combobox in the designer it won't let me change the Connection property for MySqlCmd to be the connection on the form. I could easily do it programmatically but I want to be able to do it w/ the designer. Maybe that will clear it up a little?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top