private void BrowseFolder() { bool isBottomRow = (dgvValuesList.CurrentCell.RowIndex == dgvValuesList.Rows.Count - 1); if (!isBottomRow && dgvValuesList.CurrentCell.Value != null) { string cellValue = dgvValuesList.CurrentCell.Value.ToString(); if (Directory.Exists(cellValue)) { folderBrowserDialog.SelectedPath = cellValue; } } if (folderBrowserDialog.ShowDialog() == DialogResult.OK) { DgvBrowseFolderCommand browseFolderCommand = null; int rowIndex = 0; string selectedPath = folderBrowserDialog.SelectedPath; if (isBottomRow) { rowIndex = dgvHandler.AddRow(selectedPath); browseFolderCommand = new DgvBrowseFolderCommand(dgvHandler); } else { rowIndex = dgvValuesList.CurrentCell.RowIndex; object value = dgvValuesList.Rows[rowIndex].Cells[1].Value; if (value != null) { browseFolderCommand = new DgvBrowseFolderCommand(dgvHandler, dgvValuesList.Rows[rowIndex]); } else { browseFolderCommand = new DgvBrowseFolderCommand(dgvHandler); } dgvHandler.SetRowValue(rowIndex, selectedPath); dgvHandler.SetRowIcon(rowIndex, selectedPath); } browseFolderCommand.NewRow = dgvValuesList.Rows[rowIndex]; AddCommand(browseFolderCommand); } }
/// <summary> /// Handles Control Click Events. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void BtnClick(object sender, EventArgs e) { ICommand currentCommand = null; if (sender.Equals(btnCancel)) { this.Close(); } else if (sender.Equals(btnUndo)) { commandsList.Undo(); } else if (sender.Equals(btnRedo)) { commandsList.Redo(); } else if (sender.Equals(btnSave)) { SaveEnvironmentVariable(); } else if (sender.Equals(btnExport)) { ExportEnvironmentVariable(); } else if (sender.Equals(btnImport)) { ImportEnvironmentVariable(); } else if (sender.Equals(tsmiLocate)) { LocateInWindowsExplorer(); } else if (sender.Equals(tsmiCut)) { var index = dgvValuesList.SelectedRows[0].Index; if (index != -1) { if (dgvValuesList[1, index].Value != null) { Clipboard.SetText(dgvValuesList[1, index].Value.ToString()); dgvValuesList.Rows.RemoveAt(index); } } } else if (sender.Equals(tsmiCopy)) { var index = dgvValuesList.SelectedRows[0].Index; if (index != -1) { if (dgvValuesList[1, index].Value != null) { Clipboard.SetText(dgvValuesList[1, index].Value.ToString()); } } } else if (sender.Equals(tsmiPaste)) { var index = dgvValuesList.SelectedRows[0].Index; if (index != -1) { string dgvValue = Clipboard.GetText(); string cmdValue = dgvValuesList[1, index].Value as string; if (cmdValue == null) { dgvValuesList[0, dgvValuesList.Rows.Add()].Value = Properties.Resources.ValTypeNull; } if (dgvValue != null && (cmdValue == null || cmdValue != dgvValue)) { dgvValuesList[1, index].Value = dgvValue; dgvHandler.SetRowIcon(index, dgvValue as string); dgvHandler.SetCellToolTip(index, dgvValue as string); } else { if (cmdValue != null) { dgvValuesList[1, index].Value = cmdValue; } SetBtnState(); } } } else if (sender.Equals(btnDelete)) { dgvValuesList_UserDeletingRow(null, null); } else if (sender.Equals(btnDelDupes)) { dgvValuesList_UserDeletingDupedRows(); } else if (sender.Equals(btnSortValues)) { dgvValuesList_UserSortRows(); } else if (sender.Equals(btnBrowse)) { BrowseFolder(); } #region Move Row else if (sender.Equals(btnMoveUp)) { currentCommand = new DgvMoveUpCommand(dgvHandler); } else if (sender.Equals(btnMoveTop)) { currentCommand = new DgvMoveToTopCommand(dgvHandler); } else if (sender.Equals(btnMoveDown)) { currentCommand = new DgvMoveDownCommand(dgvHandler); } else if (sender.Equals(btnMoveBottom)) { currentCommand = new DgvMoveToBottomCommand(dgvHandler); } #endregion Move Row if (!sender.Equals(btnCancel)) { AddCommand(currentCommand); } }