VB.Net set focus in DataGridView for a specified row
เนื่องด้วยผมหา 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 ครับ
Comments(0)