宣告

        Dim NewColumn As New DataGridViewButtonColumn

名稱="button"      

        NewColumn.Name = "button"
DGV新增Column

        DataGridView1.Columns.Insert(0, NewColumn)

       

        For i As Integer = 0 To DataGridView1.Rows.Count - 1
            Dim row As DataGridViewRow = DataGridView1.Rows(i)
            If row.IsNewRow OrElse row.Cells("CustomerID").Value.ToString.IndexOf("A") = -1 Then
                Dim txtcell As New DataGridViewTextBoxCell
                row.Cells("button") = txtcell
                txtcell.ReadOnly = True
            End If
        Next

 

按下按鈕的事件

  Private Sub DataGridView1_CellContentClick(ByVal sender As ObjectByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick       

 If e.ColumnIndex = 0 Then     

              MessageBox.Show(DataGridView1.Item("CustomerID", e.RowIndex).Value)        

     End If

      End Sub 

 

by小琳

arrow
arrow
    全站熱搜

    pdyurfof 發表在 痞客邦 留言(0) 人氣()