private void DataGridView_Click(object sender, EventArgs e) { DataGridView dgv2 = null; DataGridView.HitTestInfo hit; try { m_ClickedDGVArgs = (MouseEventArgs)e; if(m_ClickedDGVArgs.Button == System.Windows.Forms.MouseButtons.Right) { m_ClickedDGV = (DataGridView)sender; hit = m_ClickedDGV.HitTest(m_ClickedDGVArgs.X, m_ClickedDGVArgs.Y); if (hit.Type == DataGridViewHitTestType.TopLeftHeader) { DataGridViewSettings Tool = new DataGridViewSettings(); if(m_ClickedDGV.Equals(dgvStation1)) dgv2 = dgvStation2; else if(m_ClickedDGV.Equals(dgvStation2)) dgv2 = dgvStation1; if(Tool.setVisibility(m_ClickedDGV) == DialogResult.OK) { m_GUIInterface.saveSetting(m_ClickedDGV); if(dgv2 != null) { DataGridViewSettings.CloneSettings(ref m_ClickedDGV, ref dgv2); m_GUIInterface.saveSetting(dgv2); } } } else if (hit.Type == DataGridViewHitTestType.Cell) { if(m_ClickedDGV.Equals(dgvStationToStationRoutes)) { contextMenuStrip2.Show(m_ClickedDGV, m_ClickedDGVArgs.Location); } else if(m_ClickedDGV.Equals(dgvAllCommodities)) { contextMenuStrip3.Show(m_ClickedDGV, m_ClickedDGVArgs.Location); } else { contextMenuStrip1.Show(m_ClickedDGV, m_ClickedDGVArgs.Location); } } } } catch (Exception ex) { CErr.processError(ex, "Error while changing DataGridView settings"); } }
//格式化首列 private void FormatNumber(ref DataGridView dgv) { if (dgv.Equals(dgvGBNR)) //工步内容特殊处理 { FormatGBNR(); } else { for (int i = 0; i < dgv.RowCount; i++) { dgv[0, i].Value = (i + 1).ToString(); } } }