private void dataGridView1_DragDrop(object sender, DragEventArgs e) { int idx = GetRowFromPoint(e.X, e.Y); if (idx < 0 || m_selectionIdx == idx) { return; } if (e.Data.GetDataPresent(typeof(DataGridViewRow))) { DataGridViewRow row = (DataGridViewRow)e.Data.GetData(typeof(DataGridViewRow)); DataTable dt = (DataTable)dataGridView1.DataSource; var tempRow = dt.NewRow(); tempRow.ItemArray = dt.Rows[m_selectionIdx].ItemArray; this.dataGridView1.CellEnter -= new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEnter); dt.Rows.RemoveAt(m_selectionIdx); dt.Rows.InsertAt(tempRow, idx); this.dataGridView1.CellEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEnter); m_selectionIdx = idx; dataGridView1.Rows[m_selectionIdx].Selected = true; int visibleColumn = StapleInfo.GetVisibleColumn(dataGridView1); dataGridView1.CurrentCell = dataGridView1.Rows[m_selectionIdx].Cells[visibleColumn]; } }
private void btnDown_Click(object sender, EventArgs e) { int index = dataGridView1.CurrentRow.Index; if (index < dataGridView1.Rows.Count) { DataTable dt = (DataTable)dataGridView1.DataSource; var tempRow = dt.NewRow(); tempRow.ItemArray = dt.Rows[index].ItemArray; dt.Rows.RemoveAt(index); dt.Rows.InsertAt(tempRow, index + 1); dataGridView1.DataSource = dt; this.dataGridView1.CellEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEnter); m_selectionIdx = index + 1; dataGridView1.Rows[m_selectionIdx].Selected = true; int visibleColumn = StapleInfo.GetVisibleColumn(dataGridView1); dataGridView1.CurrentCell = dataGridView1.Rows[m_selectionIdx].Cells[visibleColumn]; } }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { ResetBomPanelPara(); ChangePanelPara(e.Node); if (m_preSelectedNode != null) { m_preSelectedNode.BackColor = treeView1.BackColor; } m_preSelectedNode = e.Node; e.Node.BackColor = Color.Yellow; if (!m_selecteTreeNodeFromDataGridViewRow && dataGridView1.Rows.Count > 0) { View_P_AssemblingBom bom = treeView1.SelectedNode.Tag as View_P_AssemblingBom; if (bom.父总成编码 == null) { bom.父总成编码 = ""; } int visibleColumn = StapleInfo.GetVisibleColumn(dataGridView1); for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells["父总成编码"].Value.ToString() == bom.父总成编码 && dataGridView1.Rows[i].Cells["零件编码"].Value.ToString() == bom.零件编码) { dataGridView1.ClearSelection(); dataGridView1.Rows[i].Selected = true; dataGridView1.CurrentCell = dataGridView1.Rows[i].Cells[visibleColumn]; break; } } } m_selecteTreeNodeFromDataGridViewRow = false; }