1、调出 TreeView控件 或 ListBox控件
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
private void deductGrid1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex < 0 || e.RowIndex < 0) return; if (e.ColumnIndex == 19 || e.ColumnIndex == 22 || e.ColumnIndex == 25) { Rect = deductGrid1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); this.TvEmp.Size = new Size(122,300); TvEmp.Location = new Point(Rect.X, Rect.Y); TvEmp.Visible = true; } else { TvEmp.Visible = false; } if (e.ColumnIndex == 20 || e.ColumnIndex == 23 || e.ColumnIndex == 26) { Rect = deductGrid1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); this.cmb.Size = new Size(Rect.Width , 2 * Rect.Height); cmb.Location = new Point(Rect.X, Rect.Y + Rect.Height); cmb.Items.Clear(); cmb.Items.Add("是"); cmb.Items.Add("否"); //this.cmb .Size = new Size(Rect .Width ,Rect .Height); //cmb.Location = new Point(Rect.X, Rect.Y); cmb.Visible = true; } else { cmb.Visible = false; } }
2、处理TreeView控件 选择内容赋值到单元格内
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
private void TvEmp_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (TvEmp.GetNodeAt(e.X, e.Y) == null) return; if (TvEmp.GetNodeAt(e.X, e.Y).Level < 2) { dqlib.ShowExclamation("请选择有效的信息!"); return; } if (deductGrid1.CurrentCell .ColumnIndex-1 == 18) { deductGrid1.Rows[deductGrid1.CurrentRow.Index].Cells["EmpOne"].Value = TvEmp.GetNodeAt(e.X, e.Y).Tag; deductGrid1.CurrentCell.Value = TvEmp.GetNodeAt(e.X, e.Y).Text; } if (deductGrid1.CurrentCell.ColumnIndex - 1 == 21) { deductGrid1.Rows[deductGrid1.CurrentRow.Index].Cells["EmpTwo"].Value = TvEmp.GetNodeAt(e.X, e.Y).Tag; deductGrid1.CurrentCell.Value = TvEmp.GetNodeAt(e.X, e.Y).Text; } if (deductGrid1.CurrentCell.ColumnIndex - 1 == 24) { deductGrid1.Rows[deductGrid1.CurrentRow.Index].Cells["EmpThree"].Value = TvEmp.GetNodeAt(e.X, e.Y).Tag; deductGrid1.CurrentCell.Value = TvEmp.GetNodeAt(e.X, e.Y).Text; } //deductGrid1.CurrentCell.Value = TvEmp.GetNodeAt(e.X ,e.Y).Text; //deductGrid1.CurrentCell.Tag = TvEmp.GetNodeAt(e.X, e.Y).Tag; TvEmp.Visible = false; }
3、处理ListBox控件
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
private void cmb_SelectedIndexChanged(object sender, EventArgs e) { if (cmb.SelectedItem != null) { this.deductGrid1.CurrentCell.Value = this.cmb.SelectedItem.ToString(); this.cmb.Visible = false; } }