| |

VerySource

 Forgot password?
 Register
Search
Author: liutian123

C # how to bind the drop-down box

[Copy link]

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-5 13:30:01
| Show all posts
ewrwerwerwer learning
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-5 13:45:01
| Show all posts
[Quote=Quote the reply of与血有关on the 9th floor:]
this.combobox.datasource=dataset1.tables[ "tablename "];
this.combobox.displaymember=dataset1.tables[ "tablename "].columns[ "name "].tostring();
this.combobox.tag=dataset1.tables[ "tablename "].col……
[/Quote]
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-5 14:00:02
| Show all posts
Learn to learn
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-5 14:15:01
| Show all posts
this.cboClass.DataSource = .....;
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-5 14:30:01
| Show all posts
private void MainForm_Load(object sender, EventArgs e)
        {
            //Display database information on the interface
            
            try
            {
                getInformation();//Refresh the form
                string select_sql = "select name from address book order by name";
                OleDbDataAdapter datadapter = new OleDbDataAdapter(select_sql, con);
                DataTable datable = new DataTable();
                datadapter.Fill(datable);

                comboBox1.DataSource = datable;
                comboBox1.DisplayMember = datable.Columns[0].ColumnName;//Control the display of bound values
                comboBox1.ValueMember = datable.Columns[0].ColumnName;//Control the display of bound values
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to connect to the database!");
            }
            finally
            {
                clearTextBox();//Clear the text box information
            }
        }

Where getInformation() and clearTextBox() are two methods I defined myself
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list