Comment se servir des errorProvider?

Résolu
godefrw Messages postés 56 Date d'inscription lundi 13 septembre 2004 Statut Membre Dernière intervention 20 mars 2006 - 7 oct. 2004 à 16:03
godefrw Messages postés 56 Date d'inscription lundi 13 septembre 2004 Statut Membre Dernière intervention 20 mars 2006 - 8 oct. 2004 à 18:01
Je ne me suis jamais servi de cet élément auparavant. Donc j'ai du commettre une erreur. J'ai copier coller le code de la doc de visual studio et ça ne marche pas du tout:
J'ai créer un Error provider et une textBox

protected void textBox1_Validating (object sender,
System.ComponentModel.CancelEventArgs e)
{
try
{
int x = Int32.Parse(textBox1.Text);
errorProvider1.SetError(textBox1, "");
}
catch (Exception f)
{
errorProvider1.SetError(textBox1, "Not an integer value.");
}
}

Lorsque je rentre un mot je n'obtient aucun message d'erreur. Est ce normal?

Ced

7 réponses

cs_coq Messages postés 6350 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
8 oct. 2004 à 17:48
en fait l'icone est affichée à droite du textbox, sur le panel, donc prevois la place a droite sinon elle n'est pas visible

Cocoricoooooooo !!!!
coq
MVP Visual C#
3
cs_coq Messages postés 6350 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
7 oct. 2004 à 16:51
euh, normalement avec les options par defaut et ce code tu devrais voir une icone a droite du textbox
verifie que tu n'as pas un
errorProvider1.SetError(textBox1, "");

qui s'execute juste apres

Cocoricoooooooo !!!!
coq
MVP Visual C#
0
Arthenius Messages postés 1182 Date d'inscription mercredi 21 janvier 2004 Statut Membre Dernière intervention 6 septembre 2011 14
7 oct. 2004 à 16:57
est ce que ton evenement textBox1_Validating est bien ratache a ton textbox ????

tu dois trouver kkpart dans le code générer par windows ca :
this.textBox1.Validating += new System.ComponentModel.CancelEventHandler(this.textBox1_Validating);

sinon faut le rajouter...

Arthenius

"Ce qui ne me tue pas, me rend plus fort..."
0
godefrw Messages postés 56 Date d'inscription lundi 13 septembre 2004 Statut Membre Dernière intervention 20 mars 2006
8 oct. 2004 à 10:10
Mon évènement textBox1_validating est bien rataché à ma textBox avec la ligne de code que tu m'as données.
Je n'ai que ce code là rien de plus...
Peut-être une propriété de mon errorprovider n'est pas bien intitialisée?
Ced
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Arthenius Messages postés 1182 Date d'inscription mercredi 21 janvier 2004 Statut Membre Dernière intervention 6 septembre 2011 14
8 oct. 2004 à 11:23
mouais c louuche...
j'ai pris ton code...

copier coller...

sur un textbox....

qd je fais mon tab pour passer a la zone suivante y passe dans le validating...et errorprovider est bien lancé....

tu peux poster le code complet de ta form....si c pas trop gros...
Arthenius

"Ce qui ne me tue pas, me rend plus fort..."
0
godefrw Messages postés 56 Date d'inscription lundi 13 septembre 2004 Statut Membre Dernière intervention 20 mars 2006
8 oct. 2004 à 17:36
Voilà le code de mon application: désolé si c'est un peu long.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Xml;

namespace fenetre_nom_projet
{
/// <summary>
/// Description résumée de Form2.
/// </summary>
public class forme2 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox nom;
private System.Windows.Forms.TextBox emplacement;
private System.Windows.Forms.ErrorProvider errorProvider1;
private string nom_projet;
private string nom_chemin;
private string nom_fichier_xml;
private DirectoryInfo mon_rep;

/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
private System.ComponentModel.Container components = null;

public forme2()
{
//
// Requis pour la prise en charge du Concepteur Windows Forms
//
InitializeComponent();

//
// TODO : ajoutez le code du constructeur après l'appel à InitializeComponent
//
}

/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.nom = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.emplacement = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.errorProvider1 = new System.Windows.Forms.ErrorProvider();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// nom
//
this.nom.Location = new System.Drawing.Point(80, 16);
this.nom.Name = "nom";
this.nom.Size = new System.Drawing.Size(192, 20);
this.nom.TabIndex = 0;
this.nom.Text = "";
this.nom.Validating += new System.ComponentModel.CancelEventHandler(this.nom_Validating);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 16);
this.label1.TabIndex = 1;
this.label1.Text = "nom";
//
// panel1
//
this.panel1.Controls.Add(this.button2);
this.panel1.Controls.Add(this.button1);
this.panel1.Controls.Add(this.emplacement);
this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.nom);
this.panel1.Location = new System.Drawing.Point(16, 32);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(280, 208);
this.panel1.TabIndex = 2;
//
// button2
//
this.button2.Location = new System.Drawing.Point(96, 96);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(72, 24);
this.button2.TabIndex = 5;
this.button2.Text = "ok";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(200, 48);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 24);
this.button1.TabIndex = 4;
this.button1.Text = "parcourir";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// emplacement
//
this.emplacement.Location = new System.Drawing.Point(80, 48);
this.emplacement.Name = "emplacement";
this.emplacement.Size = new System.Drawing.Size(112, 20);
this.emplacement.TabIndex = 3;
this.emplacement.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(0, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 32);
this.label2.TabIndex = 2;
this.label2.Text = "emplacement:";
//
// errorProvider1
//
this.errorProvider1.ContainerControl = this;
//
// forme2
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(296, 266);
this.Controls.Add(this.panel1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "forme2";
this.Text = "Nouveau projet";
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion
static void Main()
{
Application.Run(new forme2());
}

private void button1_Click(object sender, System.EventArgs e)
{
FolderBrowserDialog Folder1 = new FolderBrowserDialog();

if ( Folder1.ShowDialog() == DialogResult.OK )
{
//affichage dans la textBox
emplacement.Text = Folder1.SelectedPath;
//sauvegarde des donnéees dans les attributs de la fenêtre
nom_chemin = Folder1.SelectedPath;

}
}
public string get_chemin()
{
return nom_chemin;
}

public string get_nom_projet()
{
return nom_projet;
}

public string get_fichier_xml()
{
return nom_fichier_xml;
}

public void button2_Click(object sender, System.EventArgs e)
{
if(nom.Text != "")
{
nom_projet = nom.Text;
//creation du repertoire Oasis
mon_rep = new DirectoryInfo(String.Concat(nom_chemin, @"", nom_projet));
mon_rep.Create();
// creation du fichier xml
nom_fichier_xml = String.Concat(nom_chemin, @"/", nom_projet, @"/annotations.xml");
XmlTextWriter tr = new XmlTextWriter(nom_fichier_xml, null);
tr.Formatting = Formatting.Indented;
tr.Flush();
tr.Close();

this.DialogResult = DialogResult.OK;
}
}

protected void nom_Validating (object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
int x = Int32.Parse(nom.Text);
errorProvider1.SetError(this.nom, "");
}
catch (Exception f)
{
errorProvider1.SetError(this.nom, "Not an integer value.");
}
}
}
}

Ced
0
godefrw Messages postés 56 Date d'inscription lundi 13 septembre 2004 Statut Membre Dernière intervention 20 mars 2006
8 oct. 2004 à 18:01
merci
Ced
0
Rejoignez-nous