title: How to use validation in DataGridView
body: <p>In my program, when I click a particular row in DataGridView, if that row contains <code>"\"</code> it should pop up an error message that <code>"\ is not allowed in name or in path"</code>. I don't know how to do that. </p>
  
  <p>Here is the code:</p>
  
  <pre><code>namespace OVF_ImportExport
  {
      public partial class Form1 : Form
      {
  
          string sName = "";
          string sPath = "";
                  public Form1()
          {
              InitializeComponent();
          }
  
          private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
          {
  
              foreach (DataGridViewRow row in dataGridView1.SelectedRows)
              {
                   sName = row.Cells[0].Value.ToString();
                   sPath = row.Cells[1].Value.ToString();
  
              }
          }
  
          private void BtnCreate_Click(object sender, EventArgs e)
          {
              richTextBox1.Text = "";
              StreamWriter file = new StreamWriter("Export.bat");
              file.WriteLine("c: ");
              file.WriteLine("cd \\");
              file.WriteLine("cd Program Files ");
              file.WriteLine("cd VMware");
              file.WriteLine("cd VMware OVF Tool");
  
              foreach (DataGridViewRow row in dataGridView1.SelectedRows)
              {
                   sName = row.Cells[0].Value.ToString();
                   sName = sName.Trim();
                   sPath = row.Cells[1].Value.ToString();
  
                file.WriteLine("start ovftool.exe --powerOffSource vi://" + TxtUsername.Text + ":" + TxtPassword.Text + "@"
                     + TxtIP.Text + sPath + " " + "\"" + TxtBrowsepath.Text + "\\" +  sName + "\\" + sName + ".ovf" + "\"" + Environment.NewLine);
  
  
  
              }
              file.WriteLine("pause");
              MessageBox.Show("Batch File Created","Batch File");
              file.Close();
          }
  </code></pre>