winform datagridview 列链接操作

1.图片链接列

DataGridViewImageColumn column = new DataGridViewImageColumn();

dataGridView1.Columns.Add(column);

column.Name= "btnopenproject";
column.HeaderText = "操作";
column.Image = Properties.Resources.open;

//System.Drawing.Image.FromFile("C:\\Users\\DELL\\Desktop\\UserControls\\Resources\\open.png");

//打开文件所在文件夹操作
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].Name == "btnopenproject" && e.RowIndex >= 0)
            {
                DataGridViewColumn column = dataGridView1.Columns[e.ColumnIndex];
                int row = this.dataGridView1.CurrentRow.Index;
                string projectPath = FileSystemAccess.GetPath(dataGridView1.Rows[row].Cells["项目名称"].Value.ToString());
                System.Diagnostics.Process.Start(projectPath);
            }
        }

2.文字链接列

 DataGridViewLinkColumn column = new DataGridViewImageColumn();

dataGridView1.Columns.Add(column );

column .Name = "btnopenproject";
column .HeaderText = "操作";
column .DefaultCellStyle.NullValue = "打开文件";

3.按钮链接列
 DataGridViewButtonColumn column = new DataGridViewButtonColumn();

dataGridView1.Columns.Add(column );

column .Name = "btnopenproject";
column .HeaderText = "操作";
column .DefaultCellStyle.NullValue = "打开文件";

  

猜你喜欢

转载自www.cnblogs.com/yanranziruo/p/10648726.html
今日推荐