比如一个航班号(combobox)就已经规定了起飞城市和抵达城市(textbox),只要我选择一个航班号就自动在textbox中显示规定好的起飞城市和抵达城市。例如:航班号CZ1356代表广州到北京的航线,航班号CZ4568代表汕头到昆明的航线……请各位大侠帮帮忙解决一下小弟的问题!感激不尽……

解决方案 »

  1.   

    这个直接用代码实现就行了啊。
    1.定义个ArrayList,里面存储的数据结构为:
    航班号,起飞城市,抵达城市。
    2.在Combobox的Selectchanged函数中取得Combobox的数值,然后去ArrayList中查找
      

  2.   

    这个 你是用到数据库的话 就不需要楼上 那么麻烦  数据绑定就行了 比如你Combox是绑定航空号 txtbox是绑定的城市 那么他就会一一对应的。利用数据绑定也轻松的
     
      

  3.   

    我晕 你还没结贴? 今天看了下 随便写了个小示例 你看看  using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    namespace Windows
    {
        public partial class Execution : Form
        {
           
            public Execution()
            {
                
                InitializeComponent();
            }
            SqlConnection conn = Sqlconn.Sqlconnec();
            private void Execution_Load(object sender, EventArgs e)
            {
                SqlDataAdapter dape = new SqlDataAdapter("select * from 公交司机反馈信息", conn);
                DataSet ds = new DataSet();
                dape.Fill(ds);
                comboBox1.DataSource = ds.Tables[0];
                comboBox1.DisplayMember = "username";
                label3.DataBindings.Add("Text", ds.Tables[0], "Driver");
                label4.DataBindings.Add("Text", ds.Tables[0], "Driver1");
                label5.DataBindings.Add("Text", ds.Tables[0], "Driver2");
                label6.DataBindings.Add("Text", ds.Tables[0], "Driver3");
                label7.DataBindings.Add("Text", ds.Tables[0], "Driver4");
                label8.DataBindings.Add("Text", ds.Tables[0], "Driver5");
                label12.DataBindings.Add("Text", ds.Tables[0], "Driver6");
                label10.DataBindings.Add("Text", ds.Tables[0], "CirSuggestions1");
            }        private void button1_Click(object sender, EventArgs e)
            {
                object username = ((System.Data.DataRowView)comboBox1.SelectedItem)["username"];
                string str = textBox1.Text;
                string str1 = label3.Text;
                string str2 = label4.Text;
                string str3 = label5.Text;
                string str4 = label6.Text;
                string str5 = label7.Text;
                string str6 = label8.Text;
                string str7 = label12.Text;
                string str8 = label10.Text;
                if (textBox1.Text == "")
                {
                    MessageBox.Show("请写上回应", "信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }           
                SqlCommand cmm = new SqlCommand("select * from Execution where username=@username", conn);
                cmm.Parameters.AddWithValue("username", username);
                SqlDataAdapter dape = new SqlDataAdapter(cmm);
                DataSet ds=new DataSet();
                int n=dape.Fill(ds);
                if (n > 0)
                {
                    MessageBox.Show("此条信息你已处决", "信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    textBox1.Text = "";
                }
                else
                {
                    SqlCommand cmd = new SqlCommand("insert into Execution(username,Driver,Driver1,Driver2,Driver3,Driver4,Driver5,Driver6,CirSuggestions1,executionIm) values(@username,@Driver,@Driver1,@Driver2,@Driver3,@Driver4,@Driver5,@Driver6,@CirSuggestions1,@executionIm)", conn);
                    conn.Open();
                    cmd.Parameters.AddWithValue("username", username);
                    cmd.Parameters.AddWithValue("Driver", str1);
                    cmd.Parameters.AddWithValue("Driver1", str2);
                    cmd.Parameters.AddWithValue("Driver2", str3);
                    cmd.Parameters.AddWithValue("Driver3", str4);
                    cmd.Parameters.AddWithValue("Driver4", str5);
                    cmd.Parameters.AddWithValue("Driver5", str6);
                    cmd.Parameters.AddWithValue("Driver6", str7);
                    cmd.Parameters.AddWithValue("CirSuggestions1", str8);
                    cmd.Parameters.AddWithValue("executionIm", str);
                    cmd.ExecuteNonQuery();
                    cmd.Dispose();
                    conn.Close();
                    MessageBox.Show("信息处决成功", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textBox1.Text = "";
                }            
            }
      

  4.   

    如果不用数据绑定的话,那就用Dictionary这个根据键访问对象N内容的集合吧,把你的的航班号、
    起飞城市和抵达城市都包装到一个类里面,比如说包装为Flightshedule类,然后以航班号作为键,
    将Flightshedul类的对象作为值,这样你选择comBox的内容就好一一对应了!