c# - Display Error Message when dataGridView Row match textbox -
i'm trying display error message, if rows in datagridview match new value entered in . problem after add new datagridview with:
product c = new product(); tableproducts.products.add(c); productbindingsource.add(c); productbindingsource.movelast();
a new row created, , when want save it, compares row code of textbox , causes error message displayed. should compared stored in table, not 1 add new:
here code:
private void btnsave_click(object sender, eventargs e)
{ if (datagridview.currentrow.cells[0].value.tostring() == txtcode.text && txtcode.enabled == true) { messagebox.show("code exist! try one!", "message", messageboxbuttons.ok, messageboxicon.error); panel.enabled = false; defaultviewbuttons(); } else { productobindingsource.endedit(); tablaproductos.savechangesasync(); panel.enabled = false; defaultviewbuttons(); } }
use below refresh current cell's value,
datagridview.refreshedit(); datagridview.refresh();
Comments
Post a Comment