C#winform 

 
private void mainForm_Load(object sender, EventArgs e) { string sqll = "select
* from Type"; List<string> ListData = new List<string> { "张三", "里斯", "王六" };
DataGridViewComboBoxColumn column1 = new DataGridViewComboBoxColumn();
column1.Name = "Name"; column1.DataPropertyName = "Name";//对应数据源的字段
column1.HeaderText = "combox姓名"; column1.Width = 80;
this.dataGridView1.Columns.Add(column1); column1.DataSource = ListData; //数据库的
DataGridViewComboBoxColumn column12 = new DataGridViewComboBoxColumn();
column12.DisplayMember = "Type"; column12.ValueMember = "TypeID";
column12.HeaderText = "combox类型"; column12.Width = 80;
this.dataGridView1.Columns.Add(column12); column12.DataSource =
DBHelper.ExecuteTable(sqll); //文本的 DataGridViewTextBoxColumn column = new
DataGridViewTextBoxColumn(); column.Name = "Type"; column.DataPropertyName =
"TypeID";//对应数据源的字段 column.HeaderText = "文本类型"; column.Width = 80;
this.dataGridView1.Columns.Add(column); string sql = "select name 法律,t.Type
类型,description 内容 from book g,Type t where t.TypeID=g.TypeID";
dataGridView1.DataSource = DBHelper.ExecuteTable(sql); cbx1.DataSource =
DBHelper.ExecuteTable(sqll); cbx1.DisplayMember = "Type"; cbx1.ValueMember =
"TypeID"; } private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e) { ComboBox combo = e.Control as
ComboBox; if (combo != null) { combo.SelectedIndexChanged += new
EventHandler(ComboBox_SelectedIndexChanged); } } private void
ComboBox_SelectedIndexChanged(object sender, EventArgs e) { ComboBox combo =
sender as ComboBox; string selectedItem = combo.Text;//拿到选择后的值 }

技术
下载桌面版
GitHub
Gitee
SourceForge
百度网盘(提取码:draw)
云服务器优惠
华为云优惠券
腾讯云优惠券
阿里云优惠券
Vultr优惠券
站点信息
问题反馈
邮箱:[email protected]
吐槽一下
QQ群:766591547
关注微信