protected override void OnKeyUp(KeyEventArgs e, int rowIndex) { // when activated by the SPACE key, this method updates the cell's user interface if (!ReadOnly && (e.KeyData & Keys.Space) == Keys.Space) { check_state = PushButtonState.Normal; if (!IsInEditMode) { DataGridView.BeginEdit(false); } ToggleCheckState(); } }
protected override void OnContentClick(DataGridViewCellEventArgs e) { if (ReadOnly) { return; } if (!IsInEditMode) { DataGridView.BeginEdit(false); } ToggleCheckState(); }
public override void DoDefaultAction() { if (_owner == null) { throw new InvalidOperationException(SR.DataGridViewCellAccessibleObject_OwnerNotSet); } DataGridViewCell dataGridViewCell = (DataGridViewCell)Owner; DataGridView dataGridView = dataGridViewCell.DataGridView; if (dataGridViewCell is DataGridViewHeaderCell) { return; } if (dataGridView != null && dataGridViewCell.RowIndex == -1) { throw new InvalidOperationException(SR.DataGridView_InvalidOperationOnSharedCell); } Select(AccessibleSelection.TakeFocus | AccessibleSelection.TakeSelection); Debug.Assert(dataGridView.CurrentCell == dataGridViewCell, "the result of selecting the cell should have made this cell the current cell"); if (dataGridViewCell.ReadOnly) { // don't edit if the cell is read only return; } if (dataGridViewCell.EditType != null) { if (dataGridView.InBeginEdit || dataGridView.InEndEdit) { // don't enter or exit editing mode if the control // is in the middle of doing that already. return; } if (dataGridView.IsCurrentCellInEditMode) { // stop editing dataGridView.EndEdit(); } else if (dataGridView.EditMode != DataGridViewEditMode.EditProgrammatically) { // start editing dataGridView.BeginEdit(true /*selectAll*/); } } }
protected override void OnContentClick(DataGridViewCellEventArgs e) { if (ReadOnly) { return; } if (!IsInEditMode) { DataGridView.BeginEdit(false); } CheckState cs = GetCurrentValue(); if (threeState) { if (cs == CheckState.Indeterminate) { editingCellFormattedValue = CheckState.Unchecked; } else if (cs == CheckState.Checked) { editingCellFormattedValue = CheckState.Indeterminate; } else { editingCellFormattedValue = CheckState.Checked; } } else { if (cs == CheckState.Checked) { editingCellFormattedValue = false; } else { editingCellFormattedValue = true; } } editingCellValueChanged = true; }
public override void DoDefaultAction() { DataGridViewCheckBoxCell dataGridViewCell = (DataGridViewCheckBoxCell)Owner; DataGridView dataGridView = dataGridViewCell.DataGridView; if (dataGridView != null && dataGridViewCell.RowIndex == -1) { throw new InvalidOperationException(SR.DataGridView_InvalidOperationOnSharedCell); } if (!dataGridViewCell.ReadOnly && dataGridViewCell.OwningColumn != null && dataGridViewCell.OwningRow != null) { dataGridView.CurrentCell = dataGridViewCell; bool endEditMode = false; if (!dataGridView.IsCurrentCellInEditMode) { endEditMode = true; dataGridView.BeginEdit(false /*selectAll*/); } if (dataGridView.IsCurrentCellInEditMode) { if (dataGridViewCell.SwitchFormattedValue()) { dataGridViewCell.NotifyDataGridViewOfValueChange(); dataGridView.InvalidateCell(dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex); // notify MSAA clients that the default action changed if (Owner is DataGridViewCheckBoxCell checkBoxCell) { checkBoxCell.NotifyMASSClient(new Point(dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex)); } } if (endEditMode) { dataGridView.EndEdit(); } } } }
[Test] // Xamarin bug 5419 public void EditingControlShowingTest_Bound () { using (DataGridView _dataGridView = new DataGridView ()) { DataGridViewComboBoxColumn _nameComboBoxColumn; DataGridViewTextBoxColumn _firstNameTextBoxColumn; DataGridViewCheckBoxColumn _chosenCheckBoxColumn; _dataGridView.AutoGenerateColumns = false; // Add the event-handler. _dataGridView.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler (DataGridView_EditingControlShowingTest); // No columns have been found in the event-handler yet. editingControlShowingTest_FoundColumns = 0; // _nameComboBoxColumn _nameComboBoxColumn = new DataGridViewComboBoxColumn (); _nameComboBoxColumn.HeaderText = "Name"; _nameComboBoxColumn.DataPropertyName = "Name"; _dataGridView.Columns.Add (_nameComboBoxColumn); // _firstNameTextBoxColumn _firstNameTextBoxColumn = new DataGridViewTextBoxColumn (); _firstNameTextBoxColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; _firstNameTextBoxColumn.HeaderText = "First Name"; _firstNameTextBoxColumn.DataPropertyName = "FirstName"; _dataGridView.Columns.Add (_firstNameTextBoxColumn); // _chosenCheckBoxColumn _chosenCheckBoxColumn = new DataGridViewCheckBoxColumn (); _chosenCheckBoxColumn.HeaderText = "Chosen"; _chosenCheckBoxColumn.DataPropertyName = "Chosen"; _chosenCheckBoxColumn.FalseValue = "false"; _chosenCheckBoxColumn.TrueValue = "true"; _dataGridView.Columns.Add (_chosenCheckBoxColumn); // .NET requires that all possible values for combo-boxes in a column // are added to the column. _nameComboBoxColumn.Items.Add ("de Icaza"); _nameComboBoxColumn.Items.Add ("Toshok"); _nameComboBoxColumn.Items.Add ("Harper"); _nameComboBoxColumn.Items.Add ("Boswell"); // Set up the contents of the data-grid. BindingList<EcstRecord> boundData = new BindingList<EcstRecord> (); boundData.Add (new EcstRecord ("de Icaza", "Miguel", true)); boundData.Add (new EcstRecord ("Toshok", "Chris", false)); boundData.Add (new EcstRecord ("Harper", "Jackson", false)); boundData.Add (new EcstRecord ("Boswell", "Steven", true)); _dataGridView.DataSource = boundData; // For data binding to work, there needs to be a Form, apparently. Form form = new Form (); form.ShowInTaskbar = false; form.Controls.Add (_dataGridView); form.Show (); // Make sure the data-source took. // (Without the Form, instead of having four rows, the data grid // only has one row, and all its cell values are null.) Assert.AreEqual (boundData.Count, _dataGridView.Rows.Count, "1-6"); // Edit a combo-box cell. _dataGridView.CurrentCell = _dataGridView.Rows[3].Cells[0]; Assert.AreEqual (true, _dataGridView.Rows[3].Cells[0].Selected, "1-7"); Assert.AreEqual (true, _dataGridView.BeginEdit (false), "1-8"); _dataGridView.CancelEdit(); // Edit a text-box cell. _dataGridView.CurrentCell = _dataGridView.Rows[0].Cells[1]; Assert.AreEqual (false, _dataGridView.Rows[3].Cells[0].Selected, "1-9"); Assert.AreEqual (true, _dataGridView.Rows[0].Cells[1].Selected, "1-10"); Assert.AreEqual (true, _dataGridView.BeginEdit (false), "1-11"); _dataGridView.CancelEdit(); // Edit a check-box cell. _dataGridView.CurrentCell = _dataGridView.Rows[3].Cells[2]; Assert.AreEqual (false, _dataGridView.Rows[0].Cells[1].Selected, "1-12"); Assert.AreEqual (true, _dataGridView.Rows[3].Cells[2].Selected, "1-13"); Assert.AreEqual (true, _dataGridView.BeginEdit (false), "1-14"); _dataGridView.CancelEdit(); // Make sure the event-handler was called each time. // (DataGridViewCheckBoxCell isn't derived from Control, so the // EditingControlShowing event doesn't get called for it.) Assert.AreEqual (3, editingControlShowingTest_FoundColumns, "1-14"); // Get rid of the form. form.Close(); } }
[Test] // Xamarin bug 5419 public void EditingControlShowingTest_Unbound () { using (DataGridView _dataGridView = new DataGridView ()) { DataGridViewComboBoxColumn _nameComboBoxColumn; DataGridViewTextBoxColumn _firstNameTextBoxColumn; DataGridViewCheckBoxColumn _chosenCheckBoxColumn; // Add the event-handler. _dataGridView.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler (DataGridView_EditingControlShowingTest); // No columns have been found in the event-handler yet. editingControlShowingTest_FoundColumns = 0; // _nameComboBoxColumn _nameComboBoxColumn = new DataGridViewComboBoxColumn (); _nameComboBoxColumn.HeaderText = "Name"; _dataGridView.Columns.Add (_nameComboBoxColumn); // _firstNameTextBoxColumn _firstNameTextBoxColumn = new DataGridViewTextBoxColumn (); _firstNameTextBoxColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; _firstNameTextBoxColumn.HeaderText = "First Name"; _dataGridView.Columns.Add (_firstNameTextBoxColumn); // _chosenCheckBoxColumn _chosenCheckBoxColumn = new DataGridViewCheckBoxColumn (); _chosenCheckBoxColumn.HeaderText = "Chosen"; _dataGridView.Columns.Add (_chosenCheckBoxColumn); // .NET requires that all possible values for combo-boxes in a column // are added to the column. _nameComboBoxColumn.Items.Add ("de Icaza"); _nameComboBoxColumn.Items.Add ("Toshok"); _nameComboBoxColumn.Items.Add ("Harper"); _nameComboBoxColumn.Items.Add ("Boswell"); // Set up the contents of the data-grid. _dataGridView.Rows.Add ("de Icaza", "Miguel", true); _dataGridView.Rows.Add ("Toshok", "Chris", false); _dataGridView.Rows.Add ("Harper", "Jackson", false); _dataGridView.Rows.Add ("Boswell", "Steven", true); // Edit a combo-box cell. _dataGridView.CurrentCell = _dataGridView.Rows[3].Cells[0]; Assert.AreEqual (true, _dataGridView.Rows[3].Cells[0].Selected, "1-6"); Assert.AreEqual (true, _dataGridView.BeginEdit (false), "1-7"); _dataGridView.CancelEdit(); // Edit a text-box cell. _dataGridView.CurrentCell = _dataGridView.Rows[0].Cells[1]; Assert.AreEqual (false, _dataGridView.Rows[3].Cells[0].Selected, "1-8"); Assert.AreEqual (true, _dataGridView.Rows[0].Cells[1].Selected, "1-9"); Assert.AreEqual (true, _dataGridView.BeginEdit (false), "1-10"); _dataGridView.CancelEdit(); // Edit a check-box cell. _dataGridView.CurrentCell = _dataGridView.Rows[3].Cells[2]; Assert.AreEqual (false, _dataGridView.Rows[0].Cells[1].Selected, "1-11"); Assert.AreEqual (true, _dataGridView.Rows[3].Cells[2].Selected, "1-12"); Assert.AreEqual (true, _dataGridView.BeginEdit (false), "1-13"); _dataGridView.CancelEdit(); // Make sure the event-handler was called each time. // (DataGridViewCheckBoxCell isn't derived from Control, so the // EditingControlShowing event doesn't get called for it.) Assert.AreEqual (3, editingControlShowingTest_FoundColumns, "1-14"); _dataGridView.Dispose(); } }
private void SetEditMode(DataGridView dataGridView) { if (dataGridView.SelectedCells.Count > 0) { DataGridViewCell cell = dataGridView.SelectedCells[0]; dataGridView.CurrentCell = cell; dataGridView.BeginEdit(true); } }
/// <summary> /// Додавання товарк в чек або зміна кількості товару в чеку /// </summary> /// <param name="chqDGW">Таблиця чеку</param> /// <param name="artDGW">Таблиця товарів (можливе застосування фільтру до записів)</param> /// <param name="article">Запис з товаром</param> /// <param name="startTotal">Стартова кількість</param> /// <param name="artsTable">Оригінальна таблиця товарів (без затстосування фільтру до записів)</param> public static void AddArticleToCheque(DataGridView chqDGW, DataGridView artDGW, DataRow article, double startTotal, DataTable artsTable) { //winapi.Funcs.OutputDebugString("A"); if (AppConfig.TAX_AppTaxChar == null || AppConfig.TAX_AppTaxChar.Length == 0) { MMessageBox.Show("Немає податкових ставок", "InTech PayDesk", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if ((double)article["PRICE"] == 0) { MMessageBox.Show("Нульова ціна товару", "InTech PayDesk", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } /* * 1) If article exist * a) CTOT=TOT * b) TOT=startValue */ //winapi.Funcs.OutputDebugString("G"); int index = 0; bool rowIsUpdated = false; DataRow dRow = null; bool funcRezult = false; DataTable cheque = chqDGW.DataSource as DataTable; if (UserConfig.Properties[9] && startTotal == AppConfig.APP_StartTotal) startTotal = CheckByMask(article["UNIT"], startTotal); //Update existed rows //winapi.Funcs.OutputDebugString("H"); if (UserConfig.Properties[7] && cheque.Rows.Count != 0) { DataRow[] dRows = cheque.Select("ID='" + article["ID"] + "'"); if (dRows.Length != 0 && dRows[0] != null) try { dRow = dRows[0]; dRow["TMPTOT"] = dRow["TOT"]; if (UserConfig.Properties[17] || startTotal == 0.0) { Request req = new Request(dRow, startTotal); funcRezult = req.UpdateRowSource(chqDGW); req.Dispose(); //winapi.Funcs.OutputDebugString("U"); if (!funcRezult) return; } else dRow["TOT"] = GetRoundedDose(startTotal); index = cheque.Rows.IndexOf(dRow); rowIsUpdated = true; } catch (Exception ex) { WriteLog(ex, MethodInfo.GetCurrentMethod().Name); } } //Add new row if (!rowIsUpdated) { //winapi.Funcs.OutputDebugString("J"); dRow = cheque.NewRow(); dRow["ORIGPRICE"] = article["PRICE"]; //C string c = dRow["C"].ToString(); dRow.ItemArray = article.ItemArray; dRow["C"] = long.Parse(c); //TAX try { index = Array.IndexOf<char>(AppConfig.TAX_MarketColumn, dRow["VG"].ToString()[0]); } catch { index = 0; } if (index < 0) index = 0; char pch = AppConfig.TAX_AppColumn[index]; index = Array.IndexOf<char>(AppConfig.TAX_AppTaxChar, pch); if (index >= 0) { dRow["VG"] = pch; dRow["TAX_VAL"] = AppConfig.TAX_AppTaxRates[index]; dRow["USEDDISC"] = AppConfig.TAX_AppTaxDisc[index]; } if (UserConfig.Properties[17] || startTotal == 0.0) { Request req = new Request(dRow, startTotal); funcRezult = req.UpdateRowSource(chqDGW); req.Dispose(); if (!funcRezult) return; } else dRow["TOT"] = startTotal; #region Sorting article by ID and adding if (UserConfig.Properties[14] && cheque.Rows.Count != 0) { index = 0; do { if (GetIDCode(cheque.Rows[index]["ID"]) < GetIDCode(dRow["ID"])) index++; else break; } while (cheque.Rows.Count > index); cheque.Rows.InsertAt(dRow, index); } else { cheque.Rows.Add(dRow); index = cheque.Rows.Count - 1; } #endregion } //winapi.Funcs.OutputDebugString("K"); if (rowIsUpdated) index = dRow.Table.Rows.IndexOf(dRow); chqDGW.CurrentCell = chqDGW.Rows[index].Cells["TOT"]; try { object uniqueKey = article["C"]; article = (artDGW.DataSource as DataTable).Rows.Find(uniqueKey); if (article != null) index = (artDGW.DataSource as DataTable).Rows.IndexOf(article); else { artDGW.DataSource = artsTable; article = artsTable.Rows.Find(uniqueKey); index = artsTable.Rows.IndexOf(article); } artDGW.CurrentCell = artDGW.Rows[index].Cells[artDGW.Columns.GetFirstColumn(DataGridViewElementStates.Visible).Name]; } catch { } chqDGW.BeginEdit(true); if (!UserConfig.Properties[22]) chqDGW.EndEdit(); //winapi.Funcs.OutputDebugString("E"); }
public bool ProcessDGVEditShortcutKeys(DataGridView dgv, KeyEventArgs e, string cno, LookupTables lookupTables, AppSettings appSettings) { bool keyProcessed = false; // Change cursor to the wait cursor... Cursor origCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; if (e.KeyCode == Keys.D && e.Control) { Dictionary<int, int> selectedColumnMinRow = new Dictionary<int, int>(); // Processing keystroke... keyProcessed = true; foreach (DataGridViewCell cell in dgv.SelectedCells) { // If the min selected row has not been found for this column - find it now... if (!selectedColumnMinRow.ContainsKey(cell.ColumnIndex)) { int minRow = dgv.Rows.Count; ; // Find the minimum row index in this column's selected cells... minRow = cell.RowIndex; for (int i = minRow; i > -1; i--) { if (dgv.SelectedCells.Contains(dgv[cell.ColumnIndex, i])) minRow = i; } // If the user is trying to perform a copy down (CTRL+D) using the row for adding a new row as the source row - bail out now... if (dgv.Rows[minRow].IsNewRow) return false; //Save the min row for this column in the dictionary selectedColumnMinRow.Add(cell.ColumnIndex, minRow); } // object newValue = ((DataRowView)dgv.Rows[selectedColumnMinRow[cell.ColumnIndex]].DataBoundItem)[cell.ColumnIndex]; DataRowView dr = (DataRowView)cell.OwningRow.DataBoundItem; if (dr == null) //if (dgv.Rows[row].IsNewRow) { // Couldn't find a bound row so this must be the 'new row' row in the datagrid... dgv[cell.ColumnIndex, cell.RowIndex].Value = newValue; dgv.UpdateCellValue(cell.ColumnIndex, cell.RowIndex); } else { if (!dr[cell.ColumnIndex].Equals(newValue)) { // Edit the DataRow (not the DataRowView) so that row state is changed... dr.Row[cell.ColumnIndex] = newValue; } } } } if (e.KeyCode == Keys.E && e.Control) { // Processing keystroke... keyProcessed = true; DataRow dr = ((DataRowView)dgv.CurrentCell.OwningRow.DataBoundItem).Row; string columnName = dgv.CurrentCell.OwningColumn.Name; if (dr.Table.Columns[columnName].ExtendedProperties.ContainsKey("gui_hint") && dr.Table.Columns[columnName].ExtendedProperties["gui_hint"].ToString().ToUpper() == "TEXT_CONTROL") { string currentCellValue = dr[columnName].ToString(); RichTextEditor rte = new RichTextEditor(currentCellValue, false); if (rte.ShowDialog() == DialogResult.OK) { dr[columnName] = rte.RichTextMessage; } } } if (e.KeyCode == Keys.N && e.Control) { if (dgv.CurrentRow != null && dgv.CurrentRow.Selected && !dgv.CurrentRow.IsNewRow) { DataTable dt = (DataTable)((BindingSource)dgv.DataSource).DataSource; DataRow sourceRow = null; DataRow destRow = null; // Processing keystroke... keyProcessed = true; if (dt != null) { sourceRow = dt.DefaultView[dgv.CurrentRow.Index].Row; destRow = dt.NewRow(); } if (sourceRow != null) { foreach (DataColumn dc in dt.Columns) { if (!dt.PrimaryKey.Contains(dc) && !dc.ReadOnly) { switch (dc.ColumnName) { case "created_by": case "owned_by": if (string.IsNullOrEmpty(cno)) { destRow[dc] = sourceRow[dc]; } else { destRow[dc] = cno; } break; case "created_date": case "owned_date": destRow[dc] = DateTime.Now; break; case "modified_by": case "modified_date": break; default: // Column is not a required field (or is a boolean field that only allows Y or N) destRow[dc] = sourceRow[dc]; break; } } } dt.Rows.InsertAt(destRow, dgv.CurrentRow.Index + 1); //RefreshDGVRowFormatting(dgv.Rows[dgv.CurrentRow.Index + 1], ux_checkboxHighlightChanges.Checked); } } } if (e.KeyCode == Keys.OemQuotes && e.Control) { if (dgv.CurrentRow != null && dgv.CurrentRow.Index > 0) { int sourceRowIndex; DataRow sourceRow; DataRow destinationRow; // Processing keystroke... keyProcessed = true; if (dgv.CurrentRow.IsNewRow) { dgv.BeginEdit(true); sourceRowIndex = dgv.CurrentRow.Index - 1; sourceRow = ((DataRowView)dgv.Rows[sourceRowIndex].DataBoundItem).Row; destinationRow = ((DataRowView)dgv.CurrentRow.DataBoundItem).Row; } else { sourceRowIndex = dgv.CurrentRow.Index - 1; sourceRow = ((DataRowView)dgv.Rows[sourceRowIndex].DataBoundItem).Row; destinationRow = ((DataRowView)dgv.CurrentRow.DataBoundItem).Row; } if (sourceRow != null && destinationRow != null) { if (!destinationRow[dgv.CurrentCell.ColumnIndex].Equals(sourceRow[dgv.CurrentCell.ColumnIndex])) { if (!dgv.Columns[dgv.CurrentCell.ColumnIndex].ReadOnly) { destinationRow[dgv.CurrentCell.ColumnIndex] = sourceRow[dgv.CurrentCell.ColumnIndex]; } } } //RefreshDGVRowFormatting(dgv.CurrentCell.OwningRow, ux_checkboxHighlightChanges.Checked); } } if (e.KeyCode == Keys.V && e.Control) { IDataObject dataObj = Clipboard.GetDataObject(); string pasteText = ""; //string[] junk = dataObj.GetFormats(); if (dataObj.GetDataPresent(System.Windows.Forms.DataFormats.UnicodeText)) { char[] rowDelimiters = new char[] { '\r', '\n' }; char[] columnDelimiters = new char[] { '\t' }; int badRows = 0; int missingRows = 0; bool importSuccess = false; // Processing keystroke... keyProcessed = true; pasteText = dataObj.GetData(DataFormats.UnicodeText).ToString(); DataTable dt = (DataTable)((BindingSource)dgv.DataSource).DataSource; importSuccess = ImportTextToDataTableUsingKeys(pasteText, dt, rowDelimiters, columnDelimiters, out badRows, out missingRows, lookupTables, appSettings); if (!importSuccess) { // Paste the text into the DGV in 'block style' importSuccess = ImportTextToDataTableUsingBlockStyle(pasteText, dgv, rowDelimiters, columnDelimiters, out badRows, out missingRows, lookupTables, appSettings); } //RefreshMainDGVFormatting(); //RefreshForm(); } } if (e.KeyCode == Keys.C && e.Control) { string copyString = ""; // First we need to get the min/max rows and columns for the selected cells... int minCol = dgv.Columns.Count; int maxCol = -1; int minRow = dgv.Rows.Count; int maxRow = -1; // Processing keystroke... keyProcessed = true; foreach (DataGridViewCell dgvc in dgv.SelectedCells) { if (dgvc.ColumnIndex < minCol) minCol = dgvc.ColumnIndex; if (dgvc.ColumnIndex > maxCol) maxCol = dgvc.ColumnIndex; if (dgvc.RowIndex < minRow) minRow = dgvc.RowIndex; if (dgvc.RowIndex > maxRow) maxRow = dgvc.RowIndex; } // First, gather the column headers (but only if the entire row was selected)... if (dgv.SelectedRows.Count != 0) { for (int i = minCol; i <= maxCol; i++) { copyString += dgv.Columns[i].HeaderText + '\t'; //copyString += dgv.Columns[i].Name + '\t'; } // Strip the last tab and insert a newline... copyString = copyString.TrimEnd('\t'); copyString += "\r\n"; } // Now build the string to pass to the clipboard... for (int i = minRow; i <= maxRow; i++) { for (int j = minCol; j <= maxCol; j++) { switch (dgv[j, i].FormattedValueType.Name) { case "Boolean": copyString += dgv[j, i].Value.ToString() + '\t'; break; default: if (dgv[j, i].FormattedValue == null || dgv[j, i].FormattedValue.ToString().ToLower() == "[null]") { copyString += "" + '\t'; } else { copyString += dgv[j, i].FormattedValue.ToString() + '\t'; } break; } } copyString = copyString.TrimEnd('\t'); copyString += "\r\n"; } copyString = copyString.TrimEnd('\n'); copyString = copyString.TrimEnd('\r'); // Pass the new string to the clipboard... Clipboard.SetDataObject(copyString, false, 1, 1000); //RefreshMainDGVFormatting(); //RefreshForm(); } if (e.KeyCode == Keys.Delete) { // Processing keystroke... keyProcessed = true; if (dgv.SelectedRows.Count == 0) { // The user is deleting values from individual selected cells (not entire rows)... foreach (DataGridViewCell dgvc in dgv.SelectedCells) { DataRowView drv = (DataRowView)dgvc.OwningRow.DataBoundItem; if (drv == null) //if (dgv.Rows[row].IsNewRow) { dgvc.Value = ""; dgv.UpdateCellValue(dgvc.ColumnIndex, dgvc.RowIndex); //dgv[dgvc.ColumnIndex, dgvc.RowIndex].Style.BackColor = Color.Yellow; } else { if (!drv[dgvc.OwningColumn.Index].Equals(DBNull.Value)) { if (!dgvc.ReadOnly) { // Edit the DataRow (not the DataRowView) so that row state is changed... drv.Row[dgvc.OwningColumn.Index] = DBNull.Value; // For unbound text cells we have to manually clear the cell's text... if (string.IsNullOrEmpty(dgvc.OwningColumn.DataPropertyName)) dgvc.Value = ""; dgv.UpdateCellValue(dgvc.ColumnIndex, dgvc.RowIndex); //dgv[dgvc.ColumnIndex, dgvc.RowIndex].Style.BackColor = Color.Yellow; } } } //RefreshDGVRowFormatting(dgvc.OwningRow, ux_checkboxHighlightChanges.Checked); } } else { // The user is attempting to delete entire rows from the datagridview... //SharedUtils sharedUtils = new SharedUtils(lookupTables.WebServiceURL, lookupTables.Username, lookupTables.Password_ClearText, true); SharedUtils sharedUtils = new SharedUtils(_webServices.Url, _webServices.Username, _webServices.Password_ClearText, true, ""); GRINGlobal.Client.Common.GGMessageBox ggMessageBox = new GRINGlobal.Client.Common.GGMessageBox("WARNING!!! You are about to permanently delete {0} records from the central database!\n\nAre you sure you want to do this?", "Record Delete Confirmation", MessageBoxButtons.OKCancel, MessageBoxDefaultButton.Button2); ggMessageBox.Name = "UserInterfaceUtils_ProcessDGVEditShortcutKeysMessage1"; if (sharedUtils != null && sharedUtils.IsConnected) sharedUtils.UpdateControls(ggMessageBox.Controls, ggMessageBox.Name); //if (ggMessageBox.MessageText.Contains("{0}")) ggMessageBox.MessageText = string.Format(ggMessageBox.MessageText, dgv.SelectedRows.Count.ToString()); string[] argsArray = new string[100]; argsArray[0] = dgv.SelectedRows.Count.ToString(); ggMessageBox.MessageText = string.Format(ggMessageBox.MessageText, argsArray); //if (DialogResult.OK == MessageBox.Show("WARNING!!! You are about to permanently delete " + dgv.SelectedRows.Count.ToString() + " records from the central database!\n\nAre you sure you want to do this?", "Record delete confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)) if (DialogResult.OK == ggMessageBox.ShowDialog()) { foreach (DataGridViewRow dgvr in dgv.SelectedRows) { dgv.Rows.Remove(dgvr); } } e.Handled = true; } } // Restore cursor to default cursor... Cursor.Current = origCursor; return keyProcessed; }
static void Edit(DataGridView grid, string text) { grid.BeginEdit(false); grid.EditingControl.Text = text; grid.EndEdit(); }
private void setFocusForDataGridViewCell(DataGridView dgv, int rowindex, int cellIndex) { dgv.CurrentCell = dgv.Rows[rowindex].Cells[cellIndex]; dgv.CurrentCell.Selected = true; dgv.BeginEdit(true); }
private void SetCellValue(DataGridView dataGridView, int rowIndex, int columnIndex, object value) { dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex]; dataGridView.BeginEdit(true); dataGridView.CurrentCell.Value = value; dataGridView.EndEdit(); }