private void btnAdd_Click(object sender, EventArgs e) { try { string path = txtPath.Text; if (Directory.Exists(path) == true) { List <PathSource> list = this.DataSource; PathSource newPath = new PathSource(path); if (this.IsExists(newPath) == false) { this.DataSource = null; list.Add(newPath); this.DataSource = list; txtPath.Text = ""; } else { throw new Exception(Messages.AlreadyExistPathString); } } else { throw new Exception(Messages.InvalidTargetPath); } } catch (Exception ex) { MessageBox.Show(ex.Message, Messages.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private bool IsExists(PathSource newPath) { foreach (PathSource ps in this.DataSource) { if (ps.PathString.Equals(newPath.PathString, StringComparison.CurrentCultureIgnoreCase) == true) { return(true); } } return(false); }
private void mnuContextDeleteItem_Click(object sender, EventArgs e) { try { if (lstPath.SelectedIndex >= 0) { string name = lstPath.GetItemText(lstPath.SelectedItem); if (MessageBox.Show(Messages.AreYouSureDeleteItem + Environment.NewLine + name, Messages.MessageBoxTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { PathSource item = (PathSource)lstPath.SelectedItem; List <PathSource> list = this.DataSource; this.DataSource = null; list.Remove(item); this.DataSource = list; } } } catch (Exception ex) { MessageBox.Show(ex.Message, Messages.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } }