private void ButtonAddClick(object sender, RoutedEventArgs e)
        {
            try
            {
                var keyPressWindow = new KeyPressWindow();
                keyPressWindow.ShowDialog();
                if (keyPressWindow.DialogResult.HasValue && keyPressWindow.DialogResult.Value)
                {
                    //Clicked OK
                    var keyPressInfo = new KeyPressInfo();
                    keyPressInfo.LengthOfBreak = (KeyPressLength)keyPressWindow.ComboBoxBreak.SelectedItem;
                    keyPressInfo.VirtualKeyCodes = OSKeyPress.SplitStringKeyCodes(keyPressWindow.TextBoxKeyPress.Text);
                    keyPressInfo.LengthOfKeyPress = (KeyPressLength) keyPressWindow.ComboBoxKeyPressTime.SelectedItem;
                    _sortedList.Add(GetNewKeyValue(), keyPressInfo);

                    dataGridSequences.DataContext = _sortedList;
                    dataGridSequences.ItemsSource = _sortedList;
                    dataGridSequences.Items.Refresh();
                    _isDirty = true;
                }
            }
            catch (Exception ex)
            {
                Common.ShowErrorMessageBox(1065, ex);
            }
        }
 private void ButtonEditClick(object sender, RoutedEventArgs e)
 {
     try
     {
         var keyValuePair = (KeyValuePair<int, KeyPressInfo>)dataGridSequences.SelectedItem;
         var keyPressWindow = new KeyPressWindow(keyValuePair.Value);
         keyPressWindow.ShowDialog();
         if (keyPressWindow.DialogResult.HasValue && keyPressWindow.DialogResult.Value)
         {
             //Clicked OK
             if(!keyPressWindow.IsDirty)
             {
                 //User made no changes
                 return;
             }
             _sortedList[keyValuePair.Key].LengthOfBreak = (KeyPressLength)keyPressWindow.ComboBoxBreak.SelectedItem;
             _sortedList[keyValuePair.Key].VirtualKeyCodes = OSKeyPress.SplitStringKeyCodes(keyPressWindow.TextBoxKeyPress.Text);
             _sortedList[keyValuePair.Key].LengthOfKeyPress = (KeyPressLength)keyPressWindow.ComboBoxKeyPressTime.SelectedItem;
             dataGridSequences.DataContext = _sortedList;
             dataGridSequences.ItemsSource = _sortedList;
             dataGridSequences.Items.Refresh();
             _isDirty = true;
         }
     }
     catch (Exception ex)
     {
         Common.ShowErrorMessageBox(1083, ex);
     }
 }