1

我的第五列是从我们的 SQL 服务器DataGridView中提取信息。resumelink文件的名称是 resumelink 记录中唯一的东西,例如。DOC100.pdfName12.pdf。我需要将它们链接到计算机上的映射驱动器,因此,如果文件名是DOC100.pdf,则它必须是//nt/resume/DOC100.pdf. 我需要存储//nt/resume零件,然后只需添加 resumelink 字段中的内容。我有一个字段,dataGridView1_CellContentClick但它目前是空的。我不关心 pdf 的打开方式,无论是在 IE 还是 Adob​​e 中。

这是程序外观的图片。

在此处输入图像描述

namespace ResumeTest
{
public partial class Resume : Form
{
    SqlConnection conn = new SqlConnection();

    public Resume()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'iHBAPPSDataSet.HRresume' table. You can move, or remove it, as needed.
       this.hRresumeTableAdapter.Fill(this.iHBAPPSDataSet.HRresume);
       this.dataGridView1.RowsDefaultCellStyle.BackColor = Color.White;
       this.dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Aquamarine;
    }


    private void button1_Click(object sender, EventArgs e)
    {
       bindingSource1.Filter = "name LIKE '%" + name.Text + "%' AND skillset LIKE '%" + skillset.Text + "%'";
    }

    public void ClearTextBoxes(Control control)
    {
        foreach (Control c in control.Controls)
        {
            if (c is TextBox)
            {
                if (!(c.Parent is NumericUpDown))
                {
                    ((TextBox)c).Clear();
                }
            }
            else if (c is NumericUpDown)
            {
                ((NumericUpDown)c).Value = 0;
            }
            else if (c is ComboBox)
            {
                ((ComboBox)c).SelectedIndex = 0;
            }

            if (c.HasChildren)
            {
                ClearTextBoxes(c);
            }
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        ClearTextBoxes(this);
        bindingSource1.Filter = "name LIKE '%" + name.Text + "%'";
    }

    private void button3_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }

    private void button4_Click(object sender, EventArgs e)
    {
        Add f2 = new Add();
        f2.Show();
    }

    private void button6_Click(object sender, EventArgs e)
    {
        Delete f3 = new Delete();
        f3.Show();
    }

    private void refreshButton_Click(object sender, EventArgs e)
    {
        this.hRresumeTableAdapter.Fill(this.iHBAPPSDataSet.HRresume);
    }

    private void quitToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }
  }
}
4

1 回答 1

2
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
      // set the part of filename You have to add to some constant
      // or save it in some external file and read here to be able to edit this value
      // without rebuilding of the project
      const string filePreName = @"//nt/resume/";

      // get the clicked filename value
      string filename = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();

      // combine file pre name and file name
      string finalFilePath = filePreName + filename;

      // this function will start default program, which is configured in your system
      // to handle pdf files and will open selected pdf file in this program
      // to get access to this function you should reference to

      // using System.Diagnostics;

      // at the top of current class file
      Process.Start(finalFilePath);
}

或者将所有内容放在一行中:

Process.Start(@"//nt/resume/" + dataGridView1[e.ColumnIndex, e.RowIndex].Value);

PS 这不会改变数据网格中文件名的显示(我认为这甚至比//nt/resume/DOC100.pdf在一个单元格中显示长字符串更好),但会正确处理文件打开。

于 2013-03-27T19:53:29.740 回答