 |
|
DataGridViewComboBoxColumn vb.net รบกวนด้วยครับช่วงนี้มาบ่อย (มือใหม่ครับ) |
|
 |
|
|
 |
 |
|
DataGridView Column --->
Code (VB.NET)
Dim a = DataGridViewComboBoxColumn
Dim b = DataGridViewImageColumn
Dim c = DataGridViewTextBoxColumn
Dim d = DataGridViewButtonColumn
สำหรับผมมันใช้งานจริงไม่ได้สักตัวหนึ่ง (ระดับ ดาวพลูโต Advance)
วิธีการ
1. เสียเงินซื้อ Tool อทิเช่น TeleLexSex, DevExpressSex, etc..
2. สร้างเองตามใจฉัน (User Control) และจับยัดลงไปใน Cell อทิเช่น
---- แน่นอนว่า กึ๋นต้องเพียงพอ


Source Code ในเบื้องต้นก็ประมาณนี้ (Windows Application)
Code (VB.NET)
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
|
 |
 |
 |
 |
Date :
2016-08-31 11:43:48 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
...
...
...
อธิบายไปก็เท่านั้น (กลัวกึ๋นไม่เพียงพอ)
จาก #NO1 เวลาใช้งานฯ มันเป็นแบบนี้
Code (VB.NET)
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 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
คำถามก็คือถ้าผมมี DataGridView สักร้อยอันพันอัน ผมต้องเขียนโค๊ดเดิมฯ ซ้ำฯ หรือไม่?
(ผมจะไม่เขียนโค๊ดซ้ำเป็นครั้งที่ 2)
ปล. ชีวิตนี้ผมมักจะเจอโปรแกรมเมอร์ห่วยฯ เสมอ
|
 |
 |
 |
 |
Date :
2016-08-31 12:13:35 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ของแถม สำหรับ Small ComboBox สมมุติว่าชื่อ cboSmallItem
[b]Dictionary VS HybridDictionary[/b]
Code (VB.NET)
cboSmallItems.DataSource = New System.Collections.Specialized.HybridDictionary() From {{"01", "หอย"}, {"02", "งาม"}, {"03", "มาก"}}
cboSmallItems.DisplayMember = "Value"
cboSmallItems.ValueMember = "Key"
ปล. หนทางข้างหน้าอยู่ที่เราเลือกเดิน
|
 |
 |
 |
 |
Date :
2016-08-31 14:40:18 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก #NO 5 ถ้าตาดีและช่างสังเกตุ (หมายถึงว่า มีความละเอียดอ่อนในเชิงโปรแกรมมิ่ง)
เหมือนการทำกับข้าว เครื่องปรุงเหมือนกัน แต่รสมือต่างกัน
ผลลัพธ์ที่ได้ "ความอร่อยย่อมแตกต่างกัน รับรู้ด้วยลิ้น"
Code (VB.NET)
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
|
 |
 |
 |
 |
Date :
2016-08-31 14:47:17 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หากพวกเรากำลังสบายจงตบมือพลัน "แปะๆ"
|
 |
 |
 |
 |
Date :
2016-09-01 10:41:48 |
By :
bigsuntat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|