DGV中的combox
DGV中有一个combox
combox中是一些ID号,和名字,客户在操作时需要选中一个id时,也要看到名字,因为客户不知道ID是什么,ID只是程序中用的一个唯一码而已,所以要同时显示名字,
但在下次查看的时候(还在这个界面上),从数据库里查出数据出来时,怎么能让他显示对应这一条的id,或者名字??
------解决方案--------------------
你绑定名字和ID到combox控件上,显示名字,
private void Form1_Load(object sender, EventArgs e)
       {
           DataTable dt = GetData();
           //绑定字段
           this.comboBox1.DisplayMember = "UName";
           this.comboBox1.ValueMember = "UId";
           this.comboBox1.DataSource = dt;
       }
       private DataTable GetData() //获取数据
       {
           using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\db.mdb;Persist Security Info=False"))
           {
               OleDbDataAdapter adp = new OleDbDataAdapter("select * from temp", conn);
               conn.Open();
               DataTable dt = new DataTable();
               adp.Fill(dt);
               conn.Close();
               return dt;
           }
       }
获取的时候那是用那个属性。
------解决方案--------------------我用的是ImageComboboxEdit控件,用对象绑定的
       private void bindOperater()
       {
           imcboOperator.Properties.Items.Clear();
           imcboOperator.Properties.Items.Add(new DevExpress.XtraEditors.Controls.ImageComboBoxItem("请选择", (object)0));
           SystemWebService.user[] users = systemWS.getAllUsers();
           if (users != null)
           {
               foreach (SystemWebService.user u in users)
               {
                   imcboOperator.Properties.Items.Add(new DevExpress.XtraEditors.Controls.ImageComboBoxItem(u.name, (object)u.id));
               }
           }
           imcboOperator.SelectedIndex = 0;
       }
查看的时候imcboOperator.EditValue=Id;这样就可以了
------解决方案--------------------