Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Public Class Form1
Private btnSelector As New Button()
'สร้าง Buttnon
Private pCase As Integer
'สำหรับ เก็บส่วนของการเลือก Column
Private Sub SelectorClick(ByVal sender As Object, ByVal e As EventArgs)
Select Case pCase
Case 1
'value from dataGridView1_CellEnter
If True Then
MessageBox.Show("Show Dialog here!!")
Exit Select
End If
End Select
End Sub
Private Sub CreateButton(ByRef myButton As Button)
myButton.FlatStyle = FlatStyle.Flat
myButton.FlatAppearance.BorderSize = 0
myButton.Size = New Size(25, 19)
myButton.ImageAlign = ContentAlignment.MiddleCenter
myButton.FlatAppearance.MouseDownBackColor = Color.Transparent
myButton.FlatAppearance.MouseOverBackColor = Color.Transparent
myButton.BackColor = Color.Transparent
myButton.Image = Properties.resources.search3
'กำหนดรูปภาพ
'myButton.Text = "...";
myButton.Hide()
myButton.Click += New EventHandler(AddressOf Me.SelectorClick)
'--------------------------------------------
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CreateButton(btnSelector)
DataGridView1.Controls.Add(btnSelector)
End Sub
Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
If DataGridView1.Columns(e.ColumnIndex).Name = "Column1" Then
pCase = 1
Dim Loc As Rectangle = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, False)
Dim Wid As Integer = DataGridView1.CurrentCell.Size.Width
btnSelector.Location = New Point(Loc.X - 25 + Wid, Loc.Y)
btnSelector.Show()
End If
End Sub
Private Sub DataGridView1_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave
If btnSelector.Focused <> True Then
btnSelector.Hide()
End If
End Sub
End Class
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Public Class Form1
Private btnSelector As New Button()
'สร้าง Buttnon
Private pCase As Integer
'สำหรับ เก็บส่วนของการเลือก Column
Private Sub SelectorClick(ByVal sender As Object, ByVal e As EventArgs)
Select Case pCase
Case 1
'value from dataGridView1_CellEnter
If True Then
MessageBox.Show("Show Dialog here!!")
Exit Select
End If
End Select
End Sub
Private Sub CreateButton(ByRef myButton As Button)
myButton.FlatStyle = FlatStyle.Flat
myButton.FlatAppearance.BorderSize = 0
myButton.Size = New Size(30, 19)
myButton.ImageAlign = ContentAlignment.MiddleCenter
myButton.FlatAppearance.MouseDownBackColor = Color.Transparent
myButton.FlatAppearance.MouseOverBackColor = Color.Transparent
myButton.BackColor = Color.Transparent
'myButton.Image = Properties.resources.search3
myButton.Image = Image.FromFile(CurDir() + "\pic\SearchBc.png")
'กำหนดรูปภาพ
myButton.Hide()
myButton.Click += New EventHandler(AddressOf Me.SelectorClick)
'--------------------------------------------
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CreateButton(btnSelector)
DataGridView1.Controls.Add(btnSelector)
End Sub
Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
If DataGridView1.Columns(e.ColumnIndex).Name = "Column1" Then
pCase = 1
Dim Loc As Rectangle = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, False)
Dim Wid As Integer = DataGridView1.CurrentCell.Size.Width
btnSelector.Location = New Point(Loc.X - 25 + Wid, Loc.Y)
btnSelector.Show()
End If
End Sub
Private Sub DataGridView1_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave
If btnSelector.Focused <> True Then
btnSelector.Hide()
End If
End Sub
End Class
ตอนนี้รูปขึ้นละครับ
เหลือการกำหนด Event การคลิกที่ยัง Error อยู่ครับ
myButton.Click += New EventHandler(AddressOf Me.SelectorClick)