private void sP_FareDataGridView_MouseUp(object sender, MouseEventArgs e) //마우스 선택 { try { DataGridView.HitTestInfo hitTestInfo; //Hit 위치 if (e.Button == MouseButtons.Right) { hitTestInfo = sP_FareDataGridView.HitTest(e.X, e.Y); int col = hitTestInfo.ColumnIndex; int row = hitTestInfo.RowIndex; if (col < 0) col = 0; if (row < 0) row = 0; this.sP_FareDataGridView.CurrentCell = this.sP_FareDataGridView[col, row]; //선택되게 설정 ContextMenuStrip m = new ContextMenuStrip(); m.Items.Add("선택"); m.Items.Add("선택해제"); m.Items.Add("셀수정"); m.Items.Add("틀고정"); m.ItemClicked += new ToolStripItemClickedEventHandler(m_ItemClicked); m.Show(sP_FareDataGridView, new Point(e.X, e.Y)); } } catch { } } void m_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { switch (e.ClickedItem.Text) { case "선택": foreach (DataGridViewCell cell in sP_FareDataGridView.SelectedCells) { cell.OwningRow.Cells["Check"].Value = true; } break; case "선택해제": foreach (DataGridViewCell cell in sP_FareDataGridView.SelectedCells) { cell.OwningRow.Cells["Check"].Value = false; } break; case "셀수정": frmModify dlg = new frmModify(); dlg.SetCellData(sP_FareDataGridView.SelectedCells[0].Value.ToString()); //첫번째 선택값만 넘겨준다. if (dlg.ShowDialog() == DialogResult.OK) { string ReplaceValue = dlg.GetCellData;// 변경할 값 int iChange = 0; //변경여부 int iMassage = 0; foreach (DataGridViewCell cell in sP_FareDataGridView.SelectedCells) { string OrgineValue = cell.Value.ToString(); // 기준 값 int FIDX = int.Parse(cell.OwningRow.Cells["FIDX"].Value.ToString()); int CIDX = int.Parse(cell.OwningRow.Cells["CIDX"].Value.ToString()); string CellHeader = cell.OwningColumn.Name; if (OrgineValue != ReplaceValue) { int iReturn = APFQuery.UpdateFare(FIDX, CIDX, CellHeader, OrgineValue, ReplaceValue); if (iReturn == 1) { iChange = 1; //성공 } else if (iReturn == 2) // 수정준비중 { if (iMassage == 0)// 메시지 한번반 보이기 { MessageBox.Show(CellHeader + " 컬럼 변경은 준비중입니다. "); iMassage = 1; } } } } if (iChange == 1) btnSearch.PerformClick(); //Reflash } break; case "틀고정": for (int i = 0; i < sP_FareDataGridView.RowCount; i++) { if (sP_FareDataGridView.Columns[i].Frozen == true) sP_FareDataGridView.Columns[i].Frozen = false; } foreach (DataGridViewCell cell in sP_FareDataGridView.SelectedCells) { cell.OwningColumn.Frozen = true; } FARESetColorGrid(); break; default: break; } }