Ver Mensaje Individual
  #9 (permalink)  
Antiguo 11/01/2011, 16:49
LOD_Fredy
 
Fecha de Ingreso: abril-2009
Mensajes: 341
Antigüedad: 15 años
Puntos: 3
Respuesta: Ayuda para crear un subidor de archivos (imagenes) en C#

Ya logre lo que queria, dejo el codigo para arrastrar y soltar archivos y que almacene la ruta en el datagrid.

Código C++:
Ver original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10.  
  11. namespace WindowsFormsApplication1
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void Form1_Load(object sender, EventArgs e)
  21.         {
  22.             /*this.AllowDrop = true;
  23.             this.DragEnter += Form1_DragEnter;
  24.             this.DragDrop += Form1_DragDrop;*/
  25.             dataGridView1.AllowDrop = true;
  26.             dataGridView1.DragEnter += Form1_DragEnter;
  27.             dataGridView1.DragDrop += Form1_DragDrop;
  28.         }
  29.  
  30.         private void Form1_DragEnter(object sender, DragEventArgs e)
  31.         {
  32.             /*if (e.Data.GetDataPresent(DataFormats.FileDrop))
  33.             {
  34.                 e.Effect = DragDropEffects.Copy;
  35.             }
  36.             else
  37.             {
  38.                 e.Effect = DragDropEffects.None;
  39.             }*/
  40.         }
  41.  
  42.         private void Form1_DragDrop(object sender, DragEventArgs e)
  43.         {
  44.             /*if (e.Data.GetDataPresent(DataFormats.FileDrop))
  45.             {
  46.                 string[] filePaths = (string[])(e.Data.GetData(DataFormats.FileDrop));
  47.                 foreach (string fileLoc in filePaths)
  48.                 {
  49.                     // Code to read the contents of the text file
  50.                     if (File.Exists(fileLoc))
  51.                     {
  52.                         using (TextReader tr = new StreamReader(fileLoc))
  53.                         {
  54.                             MessageBox.Show(tr.ReadToEnd());
  55.                         }
  56.                     }
  57.  
  58.                 }
  59.             }*/
  60.         }
  61.  
  62.         private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  63.         {
  64.  
  65.         }
  66.  
  67.         private void dataGridView1_DragEnter(object sender, DragEventArgs e)
  68.         {
  69.             if (e.Data.GetDataPresent(DataFormats.FileDrop))
  70.             {
  71.                 e.Effect = DragDropEffects.Copy;
  72.             }
  73.             else
  74.             {
  75.                 e.Effect = DragDropEffects.None;
  76.             }
  77.         }
  78.  
  79.         private void dataGridView1_DragDrop(object sender, DragEventArgs e)
  80.         {
  81.             if (e.Data.GetDataPresent(DataFormats.FileDrop))
  82.             {
  83.                 string[] filePaths = (string[])(e.Data.GetData(DataFormats.FileDrop));
  84.                 foreach (string fileLoc in filePaths)
  85.                 {                    
  86.                     if (File.Exists(fileLoc))
  87.                     {                        
  88.                         {
  89.                             dataGridView1.Rows.Add();
  90.                             dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Value = fileLoc;
  91.                         }
  92.                     }
  93.  
  94.                 }
  95.             }
  96.         }
  97.     }
  98. }

Aunb espero ayuda con el problema de mi post anterior.

Última edición por LOD_Fredy; 11/01/2011 a las 16:57