Imports System.Windows.Forms
Public Class TextButton
Inherits UserControl
Public Event ButtonClick As EventHandler(Of TextButtonEventArgs)
Public Property myWidth As Integer = 123
Public Property myHeight As Integer = 456
Public Property myGirl As String = "หอยใหญ่/หอยงาม/หอยหอม"
Public NotInheritable Class TextButtonEventArgs : Inherits EventArgs
Public Text As String
Public Handled As Boolean
Sub New(ByVal หอยงาม As String)
Text = หอยงาม
End Sub
End Class
Private Sub button_Click(sender As Object, e As EventArgs) Handles button.Click
Dim args As New TextButtonEventArgs(InnerTextBox.Text)
RaiseEvent ButtonClick(Me, args)
If args.Handled Then
InnerTextBox.Text = args.Text
End If
InnerTextBox.Focus()
End Sub
Public Overrides Property Text() As String
Get
Return InnerTextBox.Text
End Get
Set(value As String)
InnerTextBox.Text = value
End Set
End Property
Protected Overrides Sub SetBoundsCore(x As Integer, y As Integer, width As Integer, height As Integer, specified As BoundsSpecified)
MyBase.SetBoundsCore(x, y, Math.Max(myWidth, myWidth + myHeight), myGirl, specified)
End Sub
End Class
Dim LookUpCol As New DataGridViewTextButtonColumn() With {.ValueType = GetType(String),
.HeaderText = If(curLang = "TH, "รหัส", "Code"),
.Width = 130,
.ButtonClickHandler = Sub(s1, e1)
dgvIncAMT.EndEdit()
Dim keyValue As String = dgvIncAMT.CurrentRow.Cells(curColIndex).Value
Dim lstSearch = lstMSTData.FindAll(Function(c) c.TABTYPE = "INC" AndAlso c.TABCODE = "หอยสองรู").ToList()
Dim strRetValue As String = mduControlManager.GetModPenTabSearch("ข้อมูล รายได้", {"TABCODE", "DESC", "SDESC", ""}, If(String.IsNullOrEmpty(keyValue), String.Empty, keyValue), "Model.MSTData", "BLL.MSTData", lstSearch)
If Not String.IsNullOrEmpty(strRetValue) Then
Dim strArray() = strRetValue.Split(StringManager.InfoSPC)
e1.Text = strArray(0)
dgvIncAMT.CurrentRow.Cells(2).Value = strArray(1)
e1.Handled = True
End If
End Sub
}
dgvIncAMT.Columns.Insert(0, LookUpCol)
ปล. มีหมาเป็นเพื่อนย่อมดีกว่ามีเพื่อนเป็นหมา
Date :
2016-08-31 11:58:10
By :
หน้าฮี
No. 4
Guest
จาก #NO 1 Column3 (จำนวนเงิน) ผมไม่ให้ User ป้อนเป็นตัวอักษร)
(โปรแกรมเมอร์ห่วยฯ มักจะลืมข้อนี้ไป)
Code (VB.NET)
Private Sub dgvIncAMT_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles dgvIncAMT.EditingControlShowing
If dgvIncAMT.CurrentCell.ColumnIndex = 3 Then
Dim txtedit As TextBox = DirectCast(e.Control, TextBox)
RemoveHandler txtedit.KeyPress, AddressOf txtEdit_KeyPress
AddHandler txtedit.KeyPress, AddressOf txtEdit_KeyPress
End If
End Sub
Private Sub txtEdit_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
If dgvIncAMT.CurrentCell.ColumnIndex = 3 Then
Dim txt As TextBox = DirectCast(sender, TextBox)
If e.KeyChar < "0" OrElse e.KeyChar > "9" Then
If AscW(e.KeyChar) = Keys.Back Then
e.Handled = False
Else
If e.KeyChar = "." And txt.Text.Contains(".") = False Then
e.Handled = False
ElseIf e.KeyChar = "-" And txt.Text.Contains("-") = False Then
e.Handled = False
Else
e.Handled = True
End If
End If
End If
End If
End Sub
cboSmallItems.DataSource = New System.Collections.Specialized.HybridDictionary() From {{"01", "หอย"}, {"02", "งาม"}, {"03", "มาก"}}
cboSmallItems.DisplayMember = "Value"
cboSmallItems.ValueMember = "Key"
<>
Code (VB.NET)
cboSmallItems.DisplayMember = "Value"
cboSmallItems.ValueMember = "Key"
cboSmallItems.DataSource = New System.Collections.Specialized.HybridDictionary() From {{"01", "หอย"}, {"02", "งาม"}, {"03", "มาก"}}
และ <>
Code (VB.NET)
RemoveHandler cboSmallItems.SelectedIndexChanged, AddressOf cboSmallItems_SelectedIndexChanged
cboSmallItems.DataSource = New System.Collections.Specialized.HybridDictionary() From {{"01", "หอย"}, {"02", "งาม"}, {"03", "มาก"}}
cboSmallItems.DisplayMember = "Value"
cboSmallItems.ValueMember = "Key"
AddHandler cboSmallItems.SelectedIndexChanged, AddressOf cboSmallItems_SelectedIndexChanged
Private Sub cboSmallItems_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboSmallItems.SelectedIndexChanged
End Sub