Private Sub info_com_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'ฐานข้อมูลงานซ่อมDataSet.info_com' table. You can move, or remove it, as needed.
Me.Info_comTableAdapter.Fill(Me.ฐานข้อมูลงานซ่อมDataSet.info_com)
'TODO: This line of code loads data into the 'ฐานข้อมูลงานซ่อมDataSet.info_com' table. You can move, or remove it, as needed.
Me.Info_comTableAdapter.Fill(Me.ฐานข้อมูลงานซ่อมDataSet.info_com)
Dim cnn As New OleDbCommand()
cnn = New OleDb.OleDbCommand(" Select * from info_com Order By รหัสเครื่อง")
Dim Table As New DataTable()
'DataGridView1.AutoGenerateColumns = False
'With Table.Columns
'End With
'DataGridView1.Columns.AddRange(New DataGridViewColumn())
CreateUnboundButtonColumn(DataGridView1) 'ปุ่มของตัวเองใน กีด
'DataGridView1.AllowUserToAddRows = False
'DataGridView1.DataSource = Table
' comment for/next out to display all buttons
For i As Integer = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(i).Cells("Details").Value = "Details"
DirectCast(DataGridView1.Rows(i).Cells("Details"), DataGridViewDisableButtonCell).Enabled = False
Next
End Sub
Sub ShowNameFromButton(ByVal GridView As DataGridView, ByVal e As DataGridViewCellEventArgs)
If DirectCast(GridView.Item("Details", e.RowIndex), DataGridViewDisableButtonCell).Enabled Then
MsgBox(String.Format("{0} {1}", GridView.Rows(e.RowIndex).Cells(0).Value().ToString(), GridView.Rows(e.RowIndex).Cells(1).Value().ToString()))
End If
End Sub
Private Sub CreateUnboundButtonColumn(ByVal sender As DataGridView)
Dim Column As New DataGridViewDisableButtonColumn
With Column
.HeaderText = "Details"
.Name = "Details"
.Text = "ดู"
.UseColumnTextForButtonValue = True
End With
sender.Columns.Insert(5, Column)
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If IsHeaderButtonCell(DataGridView1, e) Then
ShowNameFromButton(DataGridView1, e)
End If
End Sub
<System.Diagnostics.DebuggerStepThrough()> _
Function IsHeaderButtonCell(ByVal GridView As DataGridView, ByVal e As DataGridViewCellEventArgs) As Boolean
Return TypeOf GridView.Columns(e.ColumnIndex) Is DataGridViewButtonColumn AndAlso Not e.RowIndex = -1
End Function
Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
Dim buttonCell As DataGridViewDisableButtonCell = CType(DataGridView1.Rows(e.RowIndex).Cells("Details"), DataGridViewDisableButtonCell)
buttonCell.Enabled = True
If buttonCell.Value Is Nothing Then
buttonCell.Value = "Details"
End If
DataGridView1.Invalidate()
End Sub 'ติดตรงนี้ Column named Details cannot be found.
Private Sub DataGridView1_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave
Dim buttonCell As DataGridViewDisableButtonCell = CType(DataGridView1.Rows(e.RowIndex).Cells("Details"), DataGridViewDisableButtonCell)
buttonCell.Enabled = False
DataGridView1.Invalidate()
End Sub
Tag : Ms Access, VB.NET, VS 2012 (.NET 4.x), Windows
Private Sub CreateUnboundButtonColumn(ByVal sender As DataGridView)
Dim Column As New DataGridViewDisableButtonColumn
With Column
.HeaderText = "Details"
.Name = "Details"
.Text = "ดู"
.UseColumnTextForButtonValue = True
End With
sender.Columns.Insert(5, Column)
End Sub