anonymous method runs "too many times"
-
Greetings, Below code would do the following upon user clicks the button: if user clicks on a specific cell on the instantiated form's datagridview, the appropriate row's data is copied into the caller form's datagridview. Problem is: the anonym method is fired as many times as user clicks "this" form's button (in order to show up the other form, whose datagridview contains the data to be copied onto "this" form' gridview) BUT I'd like it to be fired only ONCE at a time. thanks for any thread, g (placing "return" didn't help) :confused:
public int I = 0; private void btnHozzaadas_Click(object sender, EventArgs e) { Guid[] array = new Guid[15]; tetelArErAnSzerk.Owner = this; tetelArErAnSzerk.anyagDataGridView.CellClick += delegate { if (tetelArErAnSzerk.anyagDataGridView.CurrentCell.OwningColumn.DataPropertyName == "AnyagHozzaadas") { DataView datatableView = felhasznAnyagSzallitasBindingSource.List as DataView; DataRowView rowView = datatableView.AddNew(); Debmut9DataSet.Felhaszn_AnyagSzallitasRow felhasznaltanyagdatarow = (felhasznaltanyagszallitasDataGridView.Rows[I].DataBoundItem as DataRowView).Row as Debmut9DataSet.Felhaszn_AnyagSzallitasRow; rowView["TetelArId"] = (tetelArBindingSource.Current as DataRowView)["TetelArId"]; felhasznaltanyagdatarow.AnyagId = new Guid(); Guid anyagid = ((tetelArErAnSzerk.anyagDataGridView.CurrentRow.DataBoundItem as DataRowView).Row as Debmut9DataSet.AnyagRow).AnyagId; array[I] = anyagid; if (I == 0) { felhasznaltanyagdatarow.AnyagId = anyagid; } if (I > 0) { for (int J = 0; J < felhasznaltanyagszallitasDataGridView.Rows.Count - 1; J++) { for (int K = 1; K < felhasznaltanyagszallitasDataGridView.Rows.Count - 1; K++) { if (J == K) { K++; } if (array[J] == array[K]) {
-
Greetings, Below code would do the following upon user clicks the button: if user clicks on a specific cell on the instantiated form's datagridview, the appropriate row's data is copied into the caller form's datagridview. Problem is: the anonym method is fired as many times as user clicks "this" form's button (in order to show up the other form, whose datagridview contains the data to be copied onto "this" form' gridview) BUT I'd like it to be fired only ONCE at a time. thanks for any thread, g (placing "return" didn't help) :confused:
public int I = 0; private void btnHozzaadas_Click(object sender, EventArgs e) { Guid[] array = new Guid[15]; tetelArErAnSzerk.Owner = this; tetelArErAnSzerk.anyagDataGridView.CellClick += delegate { if (tetelArErAnSzerk.anyagDataGridView.CurrentCell.OwningColumn.DataPropertyName == "AnyagHozzaadas") { DataView datatableView = felhasznAnyagSzallitasBindingSource.List as DataView; DataRowView rowView = datatableView.AddNew(); Debmut9DataSet.Felhaszn_AnyagSzallitasRow felhasznaltanyagdatarow = (felhasznaltanyagszallitasDataGridView.Rows[I].DataBoundItem as DataRowView).Row as Debmut9DataSet.Felhaszn_AnyagSzallitasRow; rowView["TetelArId"] = (tetelArBindingSource.Current as DataRowView)["TetelArId"]; felhasznaltanyagdatarow.AnyagId = new Guid(); Guid anyagid = ((tetelArErAnSzerk.anyagDataGridView.CurrentRow.DataBoundItem as DataRowView).Row as Debmut9DataSet.AnyagRow).AnyagId; array[I] = anyagid; if (I == 0) { felhasznaltanyagdatarow.AnyagId = anyagid; } if (I > 0) { for (int J = 0; J < felhasznaltanyagszallitasDataGridView.Rows.Count - 1; J++) { for (int K = 1; K < felhasznaltanyagszallitasDataGridView.Rows.Count - 1; K++) { if (J == K) { K++; } if (array[J] == array[K]) {
Hi, your code is hard to read without indentation, with long lines, etc. better is to use CODE PRE tags. I think the problem is every time you click the button, a delegate is ADDED to the DGVcell; you should do this only once. You may want to read my article on events (and the one on CodeRescue). :) -- modified at 17:42 Thursday 16th August, 2007
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Hi, your code is hard to read without indentation, with long lines, etc. better is to use CODE PRE tags. I think the problem is every time you click the button, a delegate is ADDED to the DGVcell; you should do this only once. You may want to read my article on events (and the one on CodeRescue). :) -- modified at 17:42 Thursday 16th August, 2007
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
Hi Luc, Thanks for your post Gonna go & read your article. Cheers