2012-09-27 19 views
0

我有一个gridview经由类和码ID的方法与代码加载柱:结合的扣式到一个图像链接中的DataGridView

  Queue objQueue = new Queue(); 
      dataGridView1.DataSource = objQueue.GetAllQueue(); 
      DataGridViewButtonColumn btnFile = new DataGridViewButtonColumn(); 
      btnFile.UseColumnTextForButtonValue = true; 
      btnFile.Name = "btnViewFile"; 
      btnFile.Text = "View"; 
      btnFile.HeaderText = "View Image"; 
      dataGridView1.Columns.Add(btnFile); 
在数据网格视图

波顿负载没有问题,但我如何可以结合此按钮可通过新设计的窗体或Windows图像和传真浏览器打开图像链接。

回答

0

这应该工作

btnFile.Click += btnFile_Click; 

现在定义btnFile_Click文件响应于流中的图像

0

溶液:

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) 
     { 
      if (e.ColumnIndex ==1) //Assuming the button column as second column, if not can change the index 
      { 
       //check if anything needs to be validated here 
       Form1 f = new Form1(); 
       f.navId = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); 
       f.Show(); 

      } 
     } 

在上面的代码,分配ID的值从使用此语句 f.navId = dataGridView1.Rows [e.RowIndex] .Cells [2] .Value.ToString();

对于这项工作,只是声明的目标形式(在此例如纳维德)公共变量

0

您可以将事件处理程序到DataGrid视图

dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick); 

,并把它处理

void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) 
     { 
      if (e.ColumnIndex == 0) //Or your Button Index location 
      { 
       MessageBox.Show("Here"); 
      } 
     } 

然后你就可以创建一个新的形式表现出来或者你想要它做的打开图像链接。