winforms - Updating a datagridview from a button in other form C# -
i have forms, form1 , form2.
in form1 have datagridview loads data database, 2 buttons, 1 filter , add row datagridview.
in form2 have comboboxes, textboxes, radiobuttons, , 4 buttons, 1 adds data, 1 remove selected row(when double clic row in datagridview form2 loaded info row), 1 cancel(close form), , last 1 update selected row modified info.
but problem i'm stucked there, don't know how update same row. i'm able add new 1 or erase one. i'm working on c# entity framework.
may me on how update selected row form?
i tried modifying code use when double clic datagridview load data in form2:
inspeccion inspeccio = new inspeccion(); inspeccio.id =int32.parse(txtnumtransaccion.text); inspeccio.vehiculo = int32.parse(cbxidvehiculo.text); inspeccio.cliente= int32.parse(cbxidcliente.text); inspeccio.ralladuras = ralladuras().tostring(); inspeccio.cantidad_combustible = cbxcombustible.text.tostring(); inspeccio.repuesta = repuesta().tostring(); inspeccio.gato = gato().tostring(); inspeccio.cristal = cristal().tostring(); inspeccio.fecha_inspeccion = datetime.parse(fecha.text); inspeccio.empleado_inspeccion = int32.parse(cbxidempleado.text); inspeccio.estado = cbxestvehiculo.text.tostring(); messagebox.show("se ha actualizado con exito.");
use static variables store row information when go form2. on returning, use static variables update same row. example:
public static int rowid; public static bool changed = false; private void rowclicked(object sender, eventargs e) { //get row id. got row id = 1 form1.rowid = 1; form2 frm = new form2(); frm.showdialog(); if(form1.changed) updaterowingridview(rowid); }
in form2 button, use following code sample:
private void updatebutton(object sender,eventargs e) { //update record// form1.changed = true; close(); }
hope you.
Comments
Post a Comment