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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -