Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cloning combobox
Message
From
01/06/2012 11:15:52
 
 
To
01/06/2012 10:05:59
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01544151
Message ID:
01545058
Views:
55
This message has been marked as a message which has helped to the initial question of the thread.
>>If you may need to do this a lot (and with controls other than a combobox) then you could use reflection to create the control and to spin through and set the properties.
>>Something like this : http://www.codeproject.com/Articles/12976/How-to-Clone-Serialize-Copy-Paste-a-Windows-Forms
>
>That would be useful.

That example may be overkill. It boils down to this:
Public Function CloneControl(control As System.Windows.Forms.Control) As System.Windows.Forms.Control
	Dim clone As System.Windows.Forms.Control = DirectCast(Activator.CreateInstance(control.[GetType]()), System.Windows.Forms.Control)

	For Each [property] As PropertyDescriptor In TypeDescriptor.GetProperties(control)
		If [property].PropertyType.IsSerializable Then
			[property].SetValue(clone, [property].GetValue(control))
		End If
	Next
	Return clone
End Function
Then:
ComboBox cb1 = new ComboBox();
            ComboBox cb2 = (ComboBox) CloneControl(cb1);
(Not tested)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform