Vider les Champs

Résolu
24 ans Messages postés 231 Date d'inscription lundi 27 novembre 2000 Statut Membre Dernière intervention 7 juillet 2008 - 18 mai 2006 à 16:51
sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 - 18 mai 2006 à 17:05
Salut tout le monde
j'ai un petit question
jai une fonction en VB.NET qui permet de vider les TextBox d'un formulaire
et coici ca definition


Public
Sub ViderChamps(
ByRef frm
As Form)








Dim
MyObject

As



Object






For



Each
MyObject

In
frm.Controls

' Iterate through elements.






If



TypeOf
MyObject

Is
TextBox 

Then

MyObject.text =




String
.Empty

'vider champs






End



If






Next






End



Sub

mais je voudrais faire le meme chose avec C# mais je n'arrive .
ya t'il un coud de main Merci D'avance

2 réponses

sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
18 mai 2006 à 17:05
public void ViderChamps(ref Form frm) {
   foreach (Object myObject in frm.Controls) {
      if (myObject is TextBox) {
         (myObject as TextBox).Text = String.Empty;
      }
   }
}

Sébastien FERRAND (
blog)
Consultant Indépendant
[Microsoft MVP Visual C#]
2
MorpionMx Messages postés 3466 Date d'inscription lundi 16 octobre 2000 Statut Membre Dernière intervention 30 octobre 2008 57
18 mai 2006 à 17:03
Salut

<hr />

public
static
void ViderChamps(
Form f)


   foreach (
Control c
in f.Controls)

      if (c
is
TextBox) c.Text =
string.Empty;
}
<hr />

Mx
MVP C# 
0
Rejoignez-nous