插入子节点:
- string isEx=this.dataGridView1.Rows[e.RowIndex].Cells["IsEx"].Value.ToString();
- if (this.dataGridView1.Columns[e.ColumnIndex].Name == "EX" && isEx=="false")
- {
- string id = this.dataGridView1.Rows[e.RowIndex].Cells["ID"].Value.ToString();
- DataTable table = GetDataTable("select * from Department where DparentId="+id);
- if (table.Rows.Count > 0)
- {
- //插入行
- this.dataGridView1.Rows.Insert(e.RowIndex+1, table.Rows.Count);
- for (int i = 0; i < table.Rows.Count; i++)
- {
- DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex + i+1];
- row.DefaultCellStyle.BackColor = Color.CadetBlue;
- row.Cells["ID"].Value = table.Rows[i]["ID"];
- row.Cells["DName"].Value = table.Rows[i]["DName"];
- row.Cells["Daddress"].Value = table.Rows[i]["Daddress"];
- row.Cells["Dtelphone"].Value = table.Rows[i]["Dtelphone"];
- }
- }
- //将IsEx设置为true,标明该节点已经展开
- this.dataGridView1.Rows[e.RowIndex].Cells["IsEx"].Value = "true";
- this.dataGridView1.Rows[e.RowIndex].Cells["EX"].Value = "-";
删