vb.net - Change datagriview cell value on CellValidating -


i change value of cell value user inputs there , trim before avoid left , right spaces on value before validated. code without feature:

private sub grid_cellvalidating(sender object, e datagridviewcellvalidatingeventargs) handles grid.cellvalidating dim newvalue = e.formattedvalue.tostring  if not grid.rows(e.rowindex).isnewrow              'and not e.rowindex = grid.newrowindex - 1     select case e.columnindex         case 1   'name             if string.isnullorempty(newvalue)                 e.cancel = true                 exit select             end if         case else     end select end if end sub 

what tried way, doesn't work:

   private sub grid_cellvalidating(sender object, e datagridviewcellvalidatingeventargs) handles grid.cellvalidating         dim newvalue = e.formattedvalue.tostring.trim   '<---trim added  'change value of cell without trims         dim aaa datagridviewcell = ctype(sender, datagridview).rows(e.rowindex).cells(e.columnindex)         aaa.value = newvalue           if not grid.rows(e.rowindex).isnewrow              'and not e.rowindex = grid.newrowindex - 1             select case e.columnindex                 case 1   'name                     if string.isnullorempty(newvalue)                          e.cancel = true                         exit select                     end if                            case else             end select         end if     end sub 

that's wrong event. cellvalidating determining whether contents of cell valid or not. cellvalidated or cellleave more suited situation.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo