vb.net - Force datagridview call row validating after finish input -
i'm creating form
bound datagridview
inside it. on form_load
or row_validating
, added new row datagridview
by:
private sub purchaseinrowadd() 'add new row datagridview dim dtrow datarow = ctype(me.dgvpurchasein.datasource, datatable).newrow() dtrow.item("invoiceid") = 0 dtrow.item("kindid") = ctype(ctype(me.dgvpurchasein.columns("colpurchasekind"), datagridviewcomboboxcolumn).datasource, datatable).rows(0)("kindid") dtrow.item("invoicesign") = "" dtrow.item("invoiceno") = "" dtrow.item("invoicedate") = new date(objcontroller.processyear, objcontroller.processmonth, 1) dtrow.item("id") = ctype(ctype(me.dgvpurchasein.columns("colpurchasecustomer"), datagridviewcomboboxcolumn).datasource, datatable).rows(0)("id") dtrow.item("product") = "" dtrow.item("price") = "0.00" dtrow.item("note") = "" dtrow.item("tax") = ctype(ctype(me.dgvpurchasein.columns("colpurchasekind"), datagridviewcomboboxcolumn).datasource, datatable).rows(0)("tax") dtrow.item("taxcode") = ctype(ctype(me.dgvpurchasein.columns("colpurchasecustomer"), datagridviewcomboboxcolumn).datasource, datatable).rows(0)("taxcode") dtrow.item("vat") = "" ctype(me.dgvpurchasein.datasource, datatable).rows.add(dtrow) end sub
the problem here is, when user finished input in new row , press enter, row_validating
hasn't been fired because there's no row below it. how can force row_validating
trigger when user finished input , press enter?
i have found this solution, doesn't suit case because don't want set enable adding
true
. want handle row adding code instead.
i found solution, subclassed datagridview
, override processdialogkey
this:
protected override bool processdialogkey(keys keydata) { if(keydata == keys.enter) { keyenterpress(this, new eventargs()); } return base.processdialogkey(keydata); }
(i wrote subclass in c#)
then handle key enter press in form
private sub purchaseincellkeydown(byval sender object, byval e eventargs) if me.dgvpurchasein.currentrow.index = me.dgvpurchasein.rows.count - 1 if purchaseinrowvalidate(me.dgvpurchasein.currentrow.index, true) me.purchaseinrowadd() me.deselectpurchasecell(me.dgvpurchasein.currentrow.index) me.dgvpurchasein.rows(me.dgvpurchasein.rows.count - 1).cells("colpurchasesign").selected = true end if end if end sub
this line:
me.dgvpurchasein.rows(me.dgvpurchasein.rows.count - 1).cells("colpurchasesign").selected = true
will trigger row validating
Comments
Post a Comment