Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cloning combobox
Message
De
01/06/2012 11:15:52
 
 
À
01/06/2012 10:05:59
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01544151
Message ID:
01545058
Vues:
56
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)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform