Пример #1
0
        /// <summary>
        /// This function tests the currently edited shortcut key to make sure it is a valid shortcut combination
        /// </summary>
        /// <param name="dgv">A handle to the Key Combination DataGridView</param>
        private void TestShortcutKey( DataGridView dgv )
        {
            // First, get the keycode for the currently edited row
            int row = dgv.CurrentCellAddress.Y;
            KeyCombo com = new KeyCombo( ( bool )dgv[ 0, row ].EditedFormattedValue, ( bool )dgv[ 1, row ].EditedFormattedValue, ( string )dgv[ 2, row ].EditedFormattedValue );

            // If this combo is the same as the backup version... it never changed
            if ( ( com._mainKey == keyCommandsBackup[ row ]._mainKey ) &&
                 ( com._alt == keyCommandsBackup[ row ]._alt ) &&
                 ( com._ctrl == keyCommandsBackup[ row ]._ctrl ) )                 return;

            // The function "IsValidShortcut" does the heavy lifting for this operation
            if ( com.IsValidShortcut() ) {
                // These assignments are automatic and are not explicitly needed!
                //   KeyCommand[row].Ctrl = (bool)dgv[0, row].Value;
                //   KeyCommand[row].Alt = (bool)dgv[1, row].Value;
                //   KeyCommand[row].mainKey = (string)dgv[2, row].Value;

                anyChangesMade = true;
            }
            else
            {
                // The user entered invalid data.  Restore the originally backed up combo (although this might be Keys.None)!
                dgv[ 0, row ].Value = keyCommandsBackup[ row ]._ctrl;
                dgv[ 1, row ].Value = keyCommandsBackup[ row ]._alt;
                dgv[ 2, row ].Value = keyCommandsBackup[ row ]._mainKey;
            }
        }