Archive for the 'VB.Net' Category


VB.Net set focus in DataGridView for a specified row 0

เนื่องด้วยผมหา Code ให้ Grid ไป Focus Row ที่ผมต้องการเหมือนอย่าง Delphi ไม่ได้ (ภาษาถนัดนะนั่น) สงสัยเพราะผมยังใช้ Google ไม่เก่งพอ เลยหาวิธีการไม่เจอ ดังนั้นผมเลยใช้วิธีแบบบ้านๆ ที่ผมมั่วเอาเองแบบนี้ครับ

Dim intDB_RowIndex As Integer
intDB_RowIndex = CustomersBindingSource.Find("CUS_CODE", txtCustomerCode.Text)
 
If intDB_RowIndex > -1 Then
     dgView.ClearSelection()
     dgView.Rows(intDB_RowIndex).Selected = True
End If

เพียงเท่านี้ Grid ของเราก็จะไป Focus ที่ Row นั้นแล้วครับ โดยที่ถ้ามันค้นหาไม่เจอ Function Find จะ Return ออกมาเป็น -1 ครับ

Clear ค่า Object ต่างๆ ทุกตัวใน GroupBox 0

คำสั่งด้านล่างนี้เอาไว้สำหรับ Clear ค่าใน Object Type ต่างๆ ที่วางอยู่ใน GroupBox ครับ เช่น TextBox, RadioButton, ComboBox, NumericUpDown ถ้าอยากเพิ่มอีก ก็เพิ่มได้เลยครับดูจากตัวอย่างน่าจะพอเข้าใจ

Read more »

VB.Net กับ Thread 2

หากต้องการทำงานแล้วแสดงผลให้ User บนหน้าจอแล้วละก็ Thread เป็นทางเลือกนึงครับ
ดังตัวอย่าง

Read more »

VB.Net กับการบังคับป้อนแต่ตัวเลข 0

บางกรณีเราอยากใช้ TextBox เพื่อรับค่าจาก User และจะบังคับให้ป้อนได้ตัวเลขเท่านั้น โค้ดนี้เป็นอีกรูปแบบนึง

1
2
3
4
5
6
7
8
9
10
11
Private Sub txtSalary_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSalary.KeyPress
e.Handled = TrapKey(Asc(e.KeyChar))
End Sub
 
Private Function TrapKey(ByVal KCode As String) As Boolean
If (KCode >= 48 And KCode <= 57) Or KCode = 8 Then
TrapKey = False
Else
TrapKey = True
End If
End Function

User จะป้อนได้แต่ตัวเลข และกดเครื่องหมาย Backspace ได้