/// <summary> /// Accept or discard current value of cell editor control /// </summary> /// <param name="acceptChanges">Use the _editingControl's Text as new SubItem text or discard changes?</param> public void EndEditing(bool acceptChanges) { if (_editingControl == null) { return; } var e = new SubItemEndEditingEventArgs( _editItem, // The item being edited _editSubItem, // The subitem index being edited acceptChanges ? _editingControl.Text : // Use editControl text if changes are accepted _editItem.SubItems[_editSubItem].Text, // or the original subitem's text, if changes are discarded !acceptChanges // Cancel? ); OnSubItemEndEditing(e); if (!e.Cancel) { _editItem.SubItems[_editSubItem].Text = e.DisplayText; } _editingControl.Leave -= _editControl_Leave; _editingControl.KeyPress -= _editControl_KeyPress; _editingControl.Visible = false; _editingControl = null; _editItem = null; _editSubItem = -1; }
private void LvExpressionData_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e) { if (e.SubItem != EditableColumnIndex) { return; } var b = float.TryParse(e.DisplayText, NumberStyles.Float, LocalCulture, out var fl); if (!b || (fl < 0 || 1 < fl)) { MessageBox.Show("Please enter a number between 0 and 1.", DefaultTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); e.Cancel = true; } else { Task.Delay(TimeSpan.FromSeconds(0.2)) .ContinueWith(prevTask => { var action = new Action(() => { lvExpressionData.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); }); if (InvokeRequired) { Invoke(action); } else { action(); } }); var expression = GetSelectedFacialExpression(); if (expression != null) { expression.Data[e.Item.Text] = fl; } } }
protected void OnSubItemEndEditing(SubItemEndEditingEventArgs e) { SubItemEndEditing?.Invoke(this, e); }