ว่าด้วยเรื่อง VB.net 2005 DataGridViewCheckBoxColumn

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: ว่าด้วยเรื่อง VB.net 2005 DataGridViewCheckBoxColumn

ว่าด้วยเรื่อง VB.net 2005 DataGridViewCheckBoxColumn

โดย jataz2 » 17/11/2013 4:24 pm

เรื่องง่ายๆบางครั้งก็เป็นเรื่องยาก และทำให้เราเสียเวลาไปมาก
งานก็คือใช้ DataGridView แสดงข้อมูลจาก select query ธรรมดาๆ ที่ดึงมาจาก DB เเล้วเพิ่ม checkbox เเต่ละเเถวให้ user เลือกได้ว่า จะเอาคนไหนบ้างเพื่อออก report ได้ตามใจ
ปัญหาก็คือ checkbox ที่ว่า กดเท่าไหร่มันก็ไม่ติ๊กเลือกสักที ผมทำหลายๆวิธี จนเจอเลยเอามาฝากเพื่อนๆ อีกอย่างถ้าจะเพิ่ม column ใน DataGridView โดยกดที่ Edit Columns เเล้วเพิ่ม column เเละเมื่อเลือกที่ Column Type หากมันมี DataGridViewButtonColumn, DataGridViewTextBoxColumn และชนิดอื่นๆ เบิ้ลอย่างละ 2 อันละก็มีปัญหาแน่ๆ เพราะจริงๆมันไม่ควรจะเเสดง เบิ้ลอย่างละ 2 อัน

โค้ด: เลือกทั้งหมด

Private Sub dtgvReport_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgvReport.CellClick

      If e.RowIndex > -1 Then
            If  (e.ColumnIndex = 0) Then
                                         'Click at CheckBox
                        Dim checkCell As DataGridViewCheckBoxCell = CType(dtgvReport.Rows(e.RowIndex).Cells("dtgvvcIsSelect"), DataGridViewCheckBoxCell)
                        Dim bol As Boolean = CType(checkCell.Value, [Boolean])
                        checkCell.Value = Not bol

            End If
      End If
End Sub

ข้างบน