locked
file paths RRS feed

  • Question

  •  private
     void
     CheckFileExists()
      {
       try
    
       {
        int
     successCount = 0;
        int
     failedCount = 0;
        string
     path = @"g:\t1"
    ;
        string
     path2;
        for
     (int
     i = 0; i < dataGridView1.Rows.Count; i++)
        {
         path2 = path + dataGridView1.Rows[i].Cells[12].Value.ToString();
         if
     (File.Exists(path2))
         {
          dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Aqua;
          successCount++;
          dataGridView1.Rows[i].Cells[12].Value.ToString();//????
            
         }
         else
    
         {
          dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Red;
          CheckStatus = 1;
          if
     (CheckStatus == 1)
          {
           dataGridView1.Rows[i].Cells[12].Value.ToString();
          }
          failedCount++;
         }
        }
        MessageBox.Show(successCount +" are correct & "
    +failedCount+" are incorrect file links in imported CSV file"
    );
        
       }
       catch
    
       {
        MessageBox.Show("Fatal error"
    );
        
       }
      }
    
    I want to get all valid file links in datagridview2, please assist me to get it work. 
    Sunday, January 23, 2011 6:44 PM

Answers

  • So only chage that line of code to fill dataGridView2:

     

    //maybe before filling dgv2 you can clean it out:
    dataGridView2.Rows.Clear();
    
    //then:
    dataGridView1.Rows[i].Cells[X].Value.ToString() = path2; //THIS IS IT! WHERE X is the column in your 2nd DGV.
    
    


    As simple as that.

    • Marked as answer by Bin-ze Zhao Thursday, January 27, 2011 8:00 AM
    Monday, January 24, 2011 8:38 AM

All replies

  • You only have to assing the Value of dgv cell to the variable:

        private void CheckFileExists()
        {
          try
          {
            int successCount = 0;
            int failedCount = 0;
            string path = @"g:\t1";
            string path2;
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
              path2 = path + dataGridView1.Rows[i].Cells[12].Value.ToString();
              if (File.Exists(path2))
              {
                dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Aqua;
                successCount++;
                dataGridView1.Rows[i].Cells[12].Value.ToString() = path2; //THIS IS IT!
    
              }
              else
              {
                dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Red;
                CheckStatus = 1;
                if
              (CheckStatus == 1)
                {
                  dataGridView1.Rows[i].Cells[12].Value.ToString();
                }
                failedCount++;
              }
            }
            MessageBox.Show(successCount + " are correct & " + failedCount + " are incorrect file links in imported CSV file");
    
          }
          catch
          {
            MessageBox.Show("Fatal error");
    
          }
        }
    

    Let me know if this is it.

    Mitja

    Sunday, January 23, 2011 7:43 PM
  • No, I want to get all valid file links in anther datagridview which is 'datagridview2'. And in above code it just assign a valid file paths in a variable i.e.  'path2'.

     

    Note that all values in datagridview1 is imported from a CSV file.

    Monday, January 24, 2011 5:32 AM
  • Do you have any more notes?

     


    Success
    Cor
    Monday, January 24, 2011 8:23 AM
  • So only chage that line of code to fill dataGridView2:

     

    //maybe before filling dgv2 you can clean it out:
    dataGridView2.Rows.Clear();
    
    //then:
    dataGridView1.Rows[i].Cells[X].Value.ToString() = path2; //THIS IS IT! WHERE X is the column in your 2nd DGV.
    
    


    As simple as that.

    • Marked as answer by Bin-ze Zhao Thursday, January 27, 2011 8:00 AM
    Monday, January 24, 2011 8:38 AM