Datagridview ?

MBHEY131
MBHEY131 used Ask the Experts™
on
vb.net - vs.2012

I have a DGV with an unbound check box column that I want to set a limit on the amount of ROWS that can be checked within the DGV and during the cellclick event I am calling some code to add the "CHECKED ROWS" up - everything is fine up to this point - However when I reach 10 I want to bring the customer to a halt and UNCHECK the 11th box "THAT IS CHECKED" and not allow further input
checkbox.value = false - everything's but somehow the false setting is returning to a TRUE setting after the cellclick event ?????
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014
Commented:
Use the Cell_Validating event instead, which can be cancelled. You'd have to loop through the rows to determine which have been checked:

Dim cnt As Integer
For each dgr As Datagridviewrow in YourDGV.rows
  If Not IsDBNull(dgr.Cells("Select").Value Then
    If dgr.Cells("Select").Value = True Then
      cnt += 1
      If cnt >10 Then
        Messagebox.Show("You can select only 10 rows")
        e.Cancel = True
        Exit For
    End If
  End If
Next

Author

Commented:
this all worked very well - thanx

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial