コード例 #1
0
 private void dgvFileUpload_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         DataGridView dgv = sender as DataGridView;
         if (dgv != null & e.RowIndex != -1 && e.ColumnIndex != -1)
         {
             POPUPBUTTON_FOR_GRID col = dgv.Columns[e.ColumnIndex] as POPUPBUTTON_FOR_GRID;
             if (col != null)
             {
                 DataGridViewButtonCell b = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewButtonCell;
                 if (b != null)
                 {
                     OpenFileDialog objOpenDialog = new OpenFileDialog();
                     objOpenDialog.Title  = "Upload File";
                     objOpenDialog.Filter = "*|*";
                     if (dgv.CurrentRow.Cells["file_path"].Value != null && dgv.CurrentRow.Cells["file_path"].Value.ToString() != "")
                     {
                         // objOpenDialog.InitialDirectory = dgv.CurrentRow.Cells["file_nm"].Value.ToString();
                         objOpenDialog.InitialDirectory = System.IO.Path.GetDirectoryName(dgv.CurrentRow.Cells["file_path"].Value.ToString());
                     }
                     else
                     {
                         objOpenDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
                     }
                     objOpenDialog.RestoreDirectory = true;
                     if (objOpenDialog.ShowDialog() == DialogResult.OK)
                     {
                         dgv.CurrentRow.Cells["file_path"].Value = objOpenDialog.FileName;
                         dgv.CurrentRow.Cells["file_nm"].Value   = objOpenDialog.SafeFileName;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         AutoClosingMessageBox.Show(ex.Message, "Exception");
     }
 }
コード例 #2
0
 private void dgvFileUpload_KeyPress(object sender, KeyPressEventArgs e)
 {
     try
     {
         DataGridView dgv = sender as DataGridView;
         if (dgv != null)
         {
             POPUPBUTTON_FOR_GRID col = dgv.Columns[dgv.CurrentCell.ColumnIndex] as POPUPBUTTON_FOR_GRID;
             if (col != null)
             {
                 DataGridViewButtonCell b = dgv.CurrentCell as DataGridViewButtonCell;
                 if (b != null)
                 {
                     OpenFileDialog objOpenDialog = new OpenFileDialog();
                     objOpenDialog.Title  = "Upload File";
                     objOpenDialog.Filter = "*|*";
                     if (dgv.CurrentRow.Cells["file_path"].Value != null && dgv.CurrentRow.Cells["file_path"].Value.ToString() != "")
                     {
                         objOpenDialog.InitialDirectory = dgv.CurrentRow.Cells["file_path"].Value.ToString();
                     }
                     else
                     {
                         objOpenDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
                     }
                     if (objOpenDialog.ShowDialog() == DialogResult.OK)
                     {
                         dgv.CurrentRow.Cells["file_path"].Value = objOpenDialog.FileName;
                         dgv.CurrentRow.Cells["file_nm"].Value   = objOpenDialog.SafeFileName;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         AutoClosingMessageBox.Show(ex.Message, "Exception");
     }
 }