Afficher les valeurs une chaine de caractére dans 1 Combobox, Enum

drcmomo Messages postés 182 Date d'inscription lundi 13 mars 2006 Statut Membre Dernière intervention 25 décembre 2009 - 4 mai 2007 à 12:21
SharpMao Messages postés 1024 Date d'inscription mardi 4 février 2003 Statut Membre Dernière intervention 7 juin 2010 - 4 mai 2007 à 12:54
Bonjour tout le monde !!
Je vous expose mon probléme je dois afficher dans 1 combobox  une chaine de caractére associé a un Enum , j'arrive a afficher mon Enum , mais j'ai vraiment du mal à afficher ma chaine de caractére.

namespace

Devis{

public
enum
EnmTypeDeComposition{

[

Description(
"Sans Nomenclature")]SansNomenclature = 1,

[

Description(
"Nomenclature Simple")]NomenclatureSimple = 2,

[

Description(
"Nomenclature Paramétrée")]NomenclatureParamétrée = 3,

//SansNomenclature,

//NomenclatureSimple,

//NomenclatureParamétrée

}

class

Description
//: Attribute{

public
string Text;

public Description(
string text) { Text = text; } }

public
class
CLsGlobal1{

public
string AffecterEnumDansCombo(
Enum en) {

Type type = en.GetType();

MemberInfo[] memInfo = type.GetMember(en.ToString());

if (memInfo !=
null && memInfo.Length > 0) {

object[] attrs = memInfo[0].GetCustomAttributes(
typeof(
Description),
false);

if (attrs !=
null && attrs.Length > 0)

return ((
Description)attrs[0]).Text; }

return en.ToString(); }

}
Dans mon Frm :

override

public
void PasserDansEtat_Création(){

base.PasserDansEtat_Création();

CLsGlobal1 clsGlobal1 =
new
CLsGlobal1();

EnmTypeDeComposition cool =
EnmTypeDeComposition.SansNomenclature;
CboProduitComposé.DataSource =

Enum.GetNames(
typeof(
EnmTypeDeComposition));CboProduitComposé.SelectedIndex = 1;
}

J'arrive pas afficher Sans Nomenclature , au lieu de Sansnomenclature.

QUELQU'UN PEUT M'AIDER SVP

1 réponse

SharpMao Messages postés 1024 Date d'inscription mardi 4 février 2003 Statut Membre Dernière intervention 7 juin 2010 69
4 mai 2007 à 12:54
Hello,

Ici, il y a un post auquel Sebmafate a répondu et qui doit pouvoir t'aider (2ème réponse de Sebmafate)

Amicalement, SharpMao
0
Rejoignez-nous