Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. anonymous method runs "too many times"

anonymous method runs "too many times"

Scheduled Pinned Locked Moved C#
helpdata-structures
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gericooper
    wrote on last edited by
    #1

    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]) {

    L 1 Reply Last reply
    0
    • G gericooper

      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]) {

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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


      G 1 Reply Last reply
      0
      • L Luc Pattyn

        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


        G Offline
        G Offline
        gericooper
        wrote on last edited by
        #3

        Hi Luc, Thanks for your post Gonna go & read your article. Cheers

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups