Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / April 2005

Tip: Looking for answers? Try searching our database.

Override the name property when I drag & drop controls on component class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gabriel Lozano-Mor?n - 06 Apr 2005 11:21 GMT
Does anyone know how to override the Name property of controls that I drag &
drop on a component class? When I drag and drop tables from the server
explorer on the designer of my component class I want the name to be
<table>DataAdapter instead of sqlDataAdapter1, sqlDataAdapter2, ...

TIA

Gabriel Lozano-Mor?n
Mujdat Dinc - 06 Apr 2005 12:58 GMT
Hi. You must implement your toolbox item to do this..
by overriding CreateComponentsCore function you can do your custom
initilization or cancellation..
Here  is sample code...

[Serializable]
public class MyToolItem:System.Drawing.Design.ToolboxItem
{
 public  MyToolItem(System.Runtime.Serialization.SerializationInfo
  info, System.Runtime.Serialization.StreamingContext context)
 {
  base.Deserialize(info,context);
 }

 public MyToolItem()
 {
 }
 public MyToolItem(Type toolType):base(toolType)
 {
 }
 protected override IComponent[] CreateComponentsCore(IDesignerHost host)
 {
  //MessageBox.Show("Create component");
  string name="DesiredName";
  int i=0;
  string cName = null;
  while(cName == null)
  {
   cName = name +( (i > 0   ? i.ToString():string.Empty));
   foreach(IComponent cmp in host.Container.Components  )
   if(cmp.Site.Name == cName)
   {
    i++;
    cName=null;
    break;
   }
  }

  IComponent c =  host.CreateComponent( Type.GetType(this.TypeName),cName);
  return new IComponent[] {c};
 }
}

 [ToolboxItem(typeof( MyToolItem))]
public class MyClass:Component
{
...........................

> Does anyone know how to override the Name property of controls that I drag
> & drop on a component class? When I drag and drop tables from the server
[quoted text clipped - 4 lines]
>
> Gabriel Lozano-Mor?n
Gabriel Lozano-Mor?n - 06 Apr 2005 13:10 GMT
I have tried it but when I drag and drop a table on the designer nothing
happens.

Gabriel Lozano-Mor?n

> Hi. You must implement your toolbox item to do this..
> by overriding CreateComponentsCore function you can do your custom
[quoted text clipped - 53 lines]
>>
>> Gabriel Lozano-Mor?n
Mujdat Dinc - 06 Apr 2005 13:20 GMT
When   we use [ToolboxItem(typeof( MyToolItem))] its registered by VS when
you custimize your tool bar add it into bar.. if your component tool is
already on tool bar remove it and try to add again again or register this
tool bar in your component Site property  or  initlize  function of your
designer then you dont need to use attribute ..

System.Drawing.Design.IToolboxService  ts =
GetService(typeof(System.Drawing.Design.IToolboxService)) as
System.Drawing.Design.IToolboxService  ;
   if(ts != null)
   {
    MyToolItem ti = new MyToolItem(component.GetType());
     ti.DisplayName =   component.GetType().Name;
    ts.AddToolboxItem(ti,"MyComponents");
   }

>I have tried it but when I drag and drop a table on the designer nothing
>happens.
[quoted text clipped - 58 lines]
>>>
>>> Gabriel Lozano-Mor?n
Praveen - 21 Apr 2005 16:27 GMT
Gabriel,

Did you get this to work? I am encountering the same problem, couldn't get
my custom ToolboxItem to work properly.

Mujdat,

My cusotm component and the custom toolbox item are in a custom dll,
registered with the GAC. I tried several things - reset my toolbox, closed
all vs.net, reopened 1 vs.net, added my custom control to the toolbox and
dragged and dropped it to a web form - nothing happens - the dll reference
is added to the project reference list and the cs file also seems to be
touched, but nothing happens to the form and aspx file!

Any ideas?

Thanks
Praveen

> When   we use [ToolboxItem(typeof( MyToolItem))] its registered by VS when
> you custimize your tool bar add it into bar.. if your component tool is
[quoted text clipped - 11 lines]
>     ts.AddToolboxItem(ti,"MyComponents");
>    }
Praveen - 21 Apr 2005 22:40 GMT
I actually figured that if you derive from WebControlToolboxItem, instead of
ToolboxItem, it works!

> Gabriel,
>
[quoted text clipped - 30 lines]
>>     ts.AddToolboxItem(ti,"MyComponents");
>>    }
Mujdat Dinc - 22 Apr 2005 10:35 GMT
Praveen,
It works in my control. Nothing wrong with ToolboxItem.

>I actually figured that if you derive from WebControlToolboxItem, instead
>of ToolboxItem, it works!
[quoted text clipped - 33 lines]
>>>     ts.AddToolboxItem(ti,"MyComponents");
>>>    }
Praveen - 22 Apr 2005 13:37 GMT
I guess you need to derive from WebControlToolboxItem if you are using this
on a WebControl derived control.

> Praveen,
> It works in my control. Nothing wrong with ToolboxItem.
>
>>I actually figured that if you derive from WebControlToolboxItem, instead
>>of ToolboxItem, it works!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.