Click here to Skip to main content
11,639,554 members (61,953 online)
Rate this: bad
Please Sign up or sign in to vote.
i want to display id in combox and their value (means its name) in textbox
for that purpose i did bellow code..

 string Query = "select id, name from LateFee";
            cmd = new SqlCommand(Query, con);

                dr = cmd.ExecuteReader();
                DataTable dt = new DataTable();
                dt.Columns.Add("id", typeof(string));
                //dt.Columns.Add("name", typeof(string));
                comboBox1.ValueMember = "id";
                comboBox1.DisplayMember = "id";
                comboBox1.DataSource = dt;
                binding = new Binding("Text", comboBox1, "Text");

but what is happing that in combox when i select id,in text box id is only appear but i want in textbox name should appear.
what should i do???
Posted 7-Apr-13 1:59am
Arifa S508
Edited 7-Apr-13 2:13am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need to change a few things,

//dt.Columns.Add("name", typeof(string));
<< uncomment that out.
comboBox1.ValueMember = "id";
should be
comboBox1.ValueMember = "name";

3)I think you need to change the binding from:
new Binding("Text", comboBox1, "Text");
new Binding("Text", comboBox1, "SelectedValue");
Member 9823122 at 7-Apr-13 8:27am
yes thanks now it is working properly ...

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

  Print Answers RSS
0 Suvendu Shekhar Giri 330
1 Sergey Alexandrovich Kryukov 244
2 CPallini 177
3 F-ES Sitecore 170
4 himanshu agarwal 167
0 OriginalGriff 9,081
1 Sergey Alexandrovich Kryukov 8,812
2 Mika Wendelius 7,027
3 Suvendu Shekhar Giri 2,650
4 F-ES Sitecore 2,548

Advertise | Privacy | Mobile
Web04 | 2.8.150731.1 | Last Updated 7 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100