C Shark

Moti Mashiah
Moti Mashiah used Ask the Experts™
on
Hi guys ,

I'm trying to fill combobox with this code:

 void Fillcomb()
        {
            var db = new rmsmasterdbtestEntities1();
            comboBox2.DisplayMember = "";
            comboBox2.ValueMember = "SuplierName";
            comboBox2.DataSource = (from c in db.Suppliers
                                    select new { c.SupplierName}).ToList();
        }

Open in new window


And I'm getting this result - please see attachment.
what am I doing wrong?

Thanks ,
Capture.JPG
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
Set the DisplayMember to SupplierName
Moti Mashiah.NET Developer

Author

Commented:
Now I did this:

void FillDept()
        {
            var db = new rmsmasterdbtestEntities1();
            combodept.DisplayMember = "supliername";
            combodept.ValueMember = "ID";
            combodept.DataSource = (from c in db.Suppliers
                                    select new { c.SupplierName }).ToList();
        }

Open in new window


And got this in the combobox - { SupplierName = A.I.RENTALS }
Senior .Net Consultant
Top Expert 2016
Commented:
1. You have a typo in you DisplayMember.
2. You are returning an anonymous type.

Try this:

void FillDept()
        {
            var db = new rmsmasterdbtestEntities1();
            combodept.DisplayMember = "SupplierName ";
            combodept.ValueMember = "ID";
            combodept.DataSource = (from c in db.Suppliers
                                    select c).ToList();
        }
Moti Mashiah.NET Developer

Author

Commented:
ohh no , thank you very much and sorry about my stupidity :)..
Moti Mashiah.NET Developer

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial