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. SelectedIndexChanged problem regarding combobox and data grid

SelectedIndexChanged problem regarding combobox and data grid

Scheduled Pinned Locked Moved C#
5 Posts 3 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.
  • D Offline
    D Offline
    dave1816
    wrote on last edited by
    #1

    Hi, I have just come across a problem where i have a block of code which exercutes when the selectedindexchange event kicks in. However, because i load my form becuase i have a datagrid and the combo box is binded the selectedindexchnage event is exercutes again making duplicate data :( . How do i approach avoiding this? I have looked at diffrent events but cant see one that wil solves my problem, any suggestions or simillar examples anyone can point me to? Many Thanks D.Arnold

    dave1816

    C D 2 Replies Last reply
    0
    • D dave1816

      Hi, I have just come across a problem where i have a block of code which exercutes when the selectedindexchange event kicks in. However, because i load my form becuase i have a datagrid and the combo box is binded the selectedindexchnage event is exercutes again making duplicate data :( . How do i approach avoiding this? I have looked at diffrent events but cant see one that wil solves my problem, any suggestions or simillar examples anyone can point me to? Many Thanks D.Arnold

      dave1816

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      If I have a situation where firing an event causes the event to fire again, or similar, I tend to use a flag to tell me when I want the event firing code to run, and when I need to ignore it.

      Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

      A 1 Reply Last reply
      0
      • C Christian Graus

        If I have a situation where firing an event causes the event to fire again, or similar, I tend to use a flag to tell me when I want the event firing code to run, and when I need to ignore it.

        Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

        A Offline
        A Offline
        a hamidy
        wrote on last edited by
        #3

        Graus is true, but i suggest you to use following when binding comboBox to a data source. you have selected index change event for combo box, you can simply de attach that event before binding comboBox or what ever causes comboBox change index event to fire. i have a combobox named "cmb1" with selectedIndexChangeded named "cmb1ChangedIndex". simply follow this cmb1.selectedIndexChanged -=selectedIndexChangeded; //do binding here for both comboBox or what ever cause comboBox selectedChanged event //to fire then cmb1.selectedIndexChanged +=selectedIndexChangeded ;

        1 Reply Last reply
        0
        • D dave1816

          Hi, I have just come across a problem where i have a block of code which exercutes when the selectedindexchange event kicks in. However, because i load my form becuase i have a datagrid and the combo box is binded the selectedindexchnage event is exercutes again making duplicate data :( . How do i approach avoiding this? I have looked at diffrent events but cant see one that wil solves my problem, any suggestions or simillar examples anyone can point me to? Many Thanks D.Arnold

          dave1816

          D Offline
          D Offline
          dave1816
          wrote on last edited by
          #4

          Right never used a flag but will research into it and also go with the bidning solution. Many thanks for you replys I will try the code the solution tonight ( fingers cross it works) I will post a heads up and let you know Thanks again:thumbsup: D.Arnold :-D

          dave1816

          D 1 Reply Last reply
          0
          • D dave1816

            Right never used a flag but will research into it and also go with the bidning solution. Many thanks for you replys I will try the code the solution tonight ( fingers cross it works) I will post a heads up and let you know Thanks again:thumbsup: D.Arnold :-D

            dave1816

            D Offline
            D Offline
            dave1816
            wrote on last edited by
            #5

            It worked:thumbsup: Took me a while though to figure out how you put the code togther, but i found a simillar method after about 2 hours of research ,lol. An example of the code i used and found was combobox1.SelectedIndexChanged -= new System.EventHandler(combobox1_SelectedIndexChanged); //here i listed my binding code as you mentioned cboRoomType.SelectedIndexChanged += new System.EventHandler(cboRoomType_SelectedIndexChanged); Works great, does the += method attach the event back to the handler then? i should stupied asking this question as it seem obvious but i want to make sure i know how it works. Many Thanks for you post again D.Arnold :-D p.s. ill be back:suss:lol

            dave1816

            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