Click here to Skip to main content
15,885,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
GeneralSelectServiceClient objservice = new GeneralSelectServiceClient();
            IEnumerable<clist> objApproverlist = objservice.GetCList(txtbox.Text);

 var result = from CList cu in objApproverlist
                             select new { CCode = (int)Enum.Parse(typeof(CList), cu.ToString()), CDescription = cu.ToString() }; //this line

                var tempValue = new { CCode = 0, CDescription = "-- Select --" };

                var list = result.ToList(); // Create mutable list

                list.Insert(0, tempValue);

  cbCurrency.DisplayMember = "CDescription"; 
            cbCurrency.ValueMember = "CCode" 
            cbCurrency.DataSource = objApproverlist.ToList();
Posted
Updated 28-Aug-15 0:18am
v2

C#
CCode = (int)Enum.Parse(typeof(EnumHere), cu.ToString())


Enum.Parse requires an enum type. You are parsing it an enumerable CList

UPDATE: User informs that CList is Enum.

ok - if
IEnumerable<clist> objApproverlist = objservice.GetCList(txtbox.Text);

is actually
IEnumerable<CList> objApproverlist = objservice.GetCList(txtbox.Text);

then you don't need that long winded way of getting the int:
var result = from CList cu in objApproverlist select new { CCode = (int)cu, CDescription = cu.ToString() };


But I have tested both ways and it works for me.

Please tell us all the types of the objects you're using

UPDATE 2:
My Test code:

C#
public enum CList
{
    a, b, c, d
}


private static void Main()
{

    IEnumerable<CList> objApproverlist = Enum.GetValues(typeof(CList)).Cast<CList>().AsEnumerable();

    var result = from CList cu in objApproverlist
                 select new { 
                        CCode = (int)Enum.Parse(typeof(CList), cu.ToString()),
                      //I also tried with:
                      //CCode = (int)cu,
                        CDescription = cu.ToString() }; 

    var tempValue = new { CCode = 0, CDescription = "-- Select --" };

    var list = result.ToList(); 

    list.Insert(0, tempValue);


    list.ForEach(a =>
    {
        Console.WriteLine("{0}\t{1}", a.CCode, a.CDescription);
    });
}


This works in both cases. I get the readout {0 a}, {1 b}, etc.
 
Share this answer
 
v3
Comments
Sathish km 28-Aug-15 7:05am    
CCode = (int)Enum.Parse(typeof(CList), cu.ToString())

EnumHere?
This is i'm using.
Andy Lanng 28-Aug-15 7:41am    
Ah, ok. do what is the lowercase clist type?
Sathish km 28-Aug-15 8:10am    
both are same i wrongly typed...
Andy Lanng 28-Aug-15 8:24am    
yeah, I figured it was a typo. I tested the code "as is" and got no error.

I'll update my solution with my test. Tell me if it differs from your code at all
Sathish km 28-Aug-15 9:04am    
ok
you have created list but assign something else as datasource!, I think you need below code
C#
cbCurrency.DataSource = list; 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900