private void LocateInWindowsExplorer( ) { EnvironmentValueValidator validator = new EnvironmentValueValidator(); string varValue = string.Empty; foreach (DataGridViewRow row in dgvValuesList.SelectedRows) { if (row.Index != dgvValuesList.Rows.Count - 1) { DataGridViewCell cell = row.Cells[1]; varValue = (cell.Value.ToString().Contains("%")) ? cell.ToolTipText : cell.Value.ToString(); switch (validator.ValueType(varValue)) { case EnvironmentValueType.Folder: { // Open Folder in Windows Explorer LocateInWindowsExplorer(varValue); } break; case EnvironmentValueType.File: { // Select File in Windows Explorer LocateInWindowsExplorer("/select," + varValue); } break; case EnvironmentValueType.Error: { // Select existing folder in the path string parentDir = Path.GetDirectoryName(varValue); while (!Directory.Exists(parentDir)) { parentDir = Path.GetDirectoryName(parentDir); } // Open Folder in Explorer LocateInWindowsExplorer(parentDir); } break; default: // TODO: Remove for multiple rows MessageBox.Show("Nothing to locate in Windows Explorer", "Validation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); break; } } } }
/// <summary> /// Returns Icon corresponding the type of the variable /// Added by Mariusz Ficek /// </summary> /// <param name="varValue">The variable value.</param> /// <returns>Icon Bitmap</returns> private Bitmap IconValueType(string varValue, ref string toolTipMsg) { Bitmap icon; switch (validator.ValueType(varValue)) { case EnvironmentValueType.Number: icon = (this.markAsAdded ? Properties.Resources.ValTypeNumberAdd : Properties.Resources.ValTypeNumber); toolTipMsg = "Number"; break; case EnvironmentValueType.String: icon = (this.markAsAdded ? Properties.Resources.ValTypeStringAdd : Properties.Resources.ValTypeString); toolTipMsg = "Word"; break; case EnvironmentValueType.Folder: icon = (this.markAsAdded ? Properties.Resources.ValTypeFolderAdd : Properties.Resources.ValTypeFolder); toolTipMsg = "Folder"; break; case EnvironmentValueType.File: icon = (this.markAsAdded ? Properties.Resources.ValTypeFileAdd : Properties.Resources.ValTypeFile); toolTipMsg = "File"; break; default: // Error icon = (this.markAsAdded ? Properties.Resources.ValTypeErrorAdd : Properties.Resources.ValTypeError); toolTipMsg = "No File or Folder found"; break; } return(icon); }