c# - WithEvents is not valid on a local variable declaration -


i trying port c# code vb, , think vb counterpart of c# code won't compile throwing error:

withevents not valid on local variable declaration.

in code, instances of custom user control being added subclass of tablelayout; number of controls added equals number of items in data source; eventhandlers attached events declared in user control:

here original c# code :

private void bindui () {     while (this.controls.count < datasource.defaultview.count)     {         var uc = new foocontrol ();          uc.beginediting += uc_beginediting;         uc.doupdate += uc_doupdate;         uc.dodelete += uc_dodelete;         uc.name = "uc" + this.controls.count.tostring ();          this.controls.add (uc);         this.setrow (uc, this.controls.count - 1);         this.setcolumn (uc, 0);             } } 

here counterpart vb code:

private sub bindui()     while me.controls.count < datasource.defaultview.count         dim withevents uc new foocontrol ' invalid code          addhandler uc.beginediting, addressof uc_beginediting         addhandler uc.doupdate, addressof uc_doupdate         addhandler uc.dodelete, addressof uc_dodelete         uc.name = "uc" + me.controls.count.tostring()          me.controls.add(uc)         me.setrow(uc, me.controls.count - 1)         me.setcolumn(uc, 0)     end while end sub 

what proper way attach listener these instances of foocontrol in vb.net ?


Comments