 |
|
สร้าง Textbox + Button อยู่ในช่องเดี่ยวกันใน Datagridview รบกวนขอคำแนะนำด้วยครับ |
|
 |
|
|
 |
 |
|
ตามหัวข้อเลยครับ
สร้าง Textbox + Button อยู่ในช่องเดี่ยวกันใน Datagridview รบกวนขอคำชีแนะด้วยครับ

อันนี้เป็นตัวอย่างจาก C# ผมไป Copy Code มาแปลงอีทีครับ
แต่มันยัง Error อยู่ไม่รู้จะแก้ตรงไหนครับ
ในส่วนของหน้าออกแบบ ทำการเพิ่มรูปภาพเสร็จหมดละ


Code Code (VB.NET)
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
แต่ในส่วนของ Code มันยัง Error อยู่ครับ
myButton.Image = Properties.resources.search3
myButton.Click += New EventHandler(AddressOf Me.SelectorClick)

อ้างอิง http://thaicodingclub.blogspot.com/2010/07/button-datagridview-step-by-step-cnet.html
Tag : .NET, Ms SQL Server 2005, VB.NET
|
ประวัติการแก้ไข 2015-11-07 10:21:45 2015-11-07 10:27:18
|
 |
 |
 |
 |
Date :
2015-11-07 10:20:41 |
By :
TheCom |
View :
2039 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
AddHandler myButton.Click, New EventHandler(AddressOf Me.SelectorClick) ได้ละครับ
|
 |
 |
 |
 |
Date :
2015-11-09 16:35:14 |
By :
TheCom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2015-11-09 16:43:13 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
  
|
 |
 |
 |
 |
Date :
2015-11-09 16:55:38 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|