How to check if Cell In Datagridview has a value and continue VB.Net -


hi code trying

  • first: find if value in column 0 "code"

  • second: if found check if column 1 "status" has value of "in" if true msgbox appears message "ticket used" if value nothing change value in

this code:

    private sub changefound()      dim findtxt string = txt_find.text     try         if datagridview2.rows.count > 0             integer = 0 datagridview2.rows.count - 1                 ' j integer = 0 datagridview2.columns.count - 1 'not using because want in code column.                 dim cellchange string = datagridview2.rows(i).cells("code").value.tostring                  if cellchange.contains(findtxt) = true                     if datagridview2.rows(i).cells("status").value = "in"    'this line 366                         msgbox("tickets used")                         exit sub                       else                         datagridview2                             ' .rows(i).cells(j).style.backcolor = color.gray                             '  .rows(i).cells(j).value = findtxt                             ' msgbox(i & j + 1)                              .rows(i).cells("status").value = "in"                               exit sub                         end                     end if                 end if                     'next   'this jfor              next         end if     catch e exception         messagebox.show(e.tostring())     end try   end sub 

any way move around check if in found msgbox used ticket. if cell has no value locks error:

system.invalidcastexception:operator'=' not defined type"dbnull" , string "in"
@ main.vb:line366

any help?

add dbnull checking before doing comparison :

..... if not isdbnull(datagridview2.rows(i).cells("status").value) _         andalso datagridview2.rows(i).cells("status").value = "in"  ..... 

read following thread more options handle dbnull data : handling dbnull data in vb.net


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -