C# combox box showing array instead of Data

Hi, I used following code to add data to Combo box, But combobox showing results
String[] Array
Where is wrong
public List<string[]> Displayadd()
        {
            List<string[]> lstpartners = new List<string[]>();
         
            string sqlPartners = "SELECT name ,address from test";

            string results = string.Empty;
            PartnerCon=dbConnect.Connect();
            PartnerCon.Open();
            SqlCommand cmdPartners = PartnerCon.CreateCommand();
            cmdPartners.CommandText = sqlPartners;

            using (SqlDataReader rdr = cmdPartners.ExecuteReader())
            {
                //List<string> mylist = new List<string>(new string[] 
                while (rdr.Read())
                {
                    lstpartners.Add(new string[] { rdr["address"].ToString(), rdr["name"].ToString() });


                }

            }


            PartnerCon.Close();



            return lstpartners;
        
        }

Open in new window


Calling Combobox

 cmbPartnerID.DataSource = null;
            Partner ptr = new Partner();
            cmbPartnerID.DataSource = ptr.DisplayAdd();
            cmbPartnerID.DisplayMember = "address";
LVL 10
ukerandiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
first, you should call:

cmbPartnerID.DataSource = ptr.DisplayAdd();

Open in new window

but not:

cmbPartnerID.DataSource = ptr.Displayadd();

Open in new window


then make the changes below:

create a Partner Info class to handle the item

class PartnerInfo
    {
        public String Address { get; set; }
        public String Name { get; set; }

        public PartnerInfo(String Address, String Name)
        {
            this.Address = Address;
            this.Name = Name;
        }
    }

Open in new window


then:

public List<PartnerInfo> DisplayAdd()
        {
            List<PartnerInfo> lstpartners = new List<PartnerInfo>();

            string sqlPartners = "SELECT name ,address from test";

            string results = string.Empty;
            
            PartnerCon = dbConnect.Connect();
            PartnerCon.Open();
            SqlCommand cmdPartners = PartnerCon.CreateCommand();
            cmdPartners.CommandText = sqlPartners;

            using (SqlDataReader rdr = cmdPartners.ExecuteReader())
            {
                while (rdr.Read())
                {
                    lstpartners.Add(new PartnerInfo(rdr["address"].ToString(), rdr["name"].ToString()));
                }
            }

            PartnerCon.Close();
            return lstpartners;
        }

Open in new window


then in your binding:

cmbPartnerID.DataSource = null;
            Partner ptr = new Partner();
            cmbPartnerID.DataSource = ptr.DisplayAdd();
            cmbPartnerID.DisplayMember = "address";

Open in new window


to get your selected value:

PartnerInfo info = (PartnerInfo)cmbPartnerID.SelectedValue;
            MessageBox.Show(info.Address + ":" + info.Name);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
do you need further assistance here?
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
as suggested solution meet the requirement
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.