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. DatagridView Multiple ComboBox issue

DatagridView Multiple ComboBox issue

Scheduled Pinned Locked Moved C#
helpdatabase
2 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.
  • K Offline
    K Offline
    kruegersck
    wrote on last edited by
    #1

    I have attached the following code. I have a datagridview with three comboboxes on it. When I select an item from the first combobox it functions as intended. The problem I am having is that when I click on the second or third combobox it executes the item_SelectedIndexChanged event as shown below. I know I am missing something stupid! Any help is appreciated! Thanks! private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { int columnindex = dataGridView1.CurrentCell.ColumnIndex; ComboBox combo; if (dataGridView1.CurrentCell.ColumnIndex == 3) { combo = e.Control as ComboBox; if (combo == null) return; combo.SelectedIndexChanged -= item_SelectedIndexChanged; combo.SelectedIndexChanged += item_SelectedIndexChanged; } } void item_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cmbBox = (ComboBox)sender; int x = Convert.ToInt32(cmbBox.SelectedIndex.ToString()); int y = dataGridView1.CurrentRow.Index; dataGridView1.Rows[y].Cells[4].Value = dsInvoice.Parts.Rows[x]["DESC"].ToString(); dataGridView1.Rows[y].Cells[5].Value = Convert.ToDecimal(dsInvoice.Parts.Rows[x]["Price"].ToString()); }

    D 1 Reply Last reply
    0
    • K kruegersck

      I have attached the following code. I have a datagridview with three comboboxes on it. When I select an item from the first combobox it functions as intended. The problem I am having is that when I click on the second or third combobox it executes the item_SelectedIndexChanged event as shown below. I know I am missing something stupid! Any help is appreciated! Thanks! private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { int columnindex = dataGridView1.CurrentCell.ColumnIndex; ComboBox combo; if (dataGridView1.CurrentCell.ColumnIndex == 3) { combo = e.Control as ComboBox; if (combo == null) return; combo.SelectedIndexChanged -= item_SelectedIndexChanged; combo.SelectedIndexChanged += item_SelectedIndexChanged; } } void item_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cmbBox = (ComboBox)sender; int x = Convert.ToInt32(cmbBox.SelectedIndex.ToString()); int y = dataGridView1.CurrentRow.Index; dataGridView1.Rows[y].Cells[4].Value = dsInvoice.Parts.Rows[x]["DESC"].ToString(); dataGridView1.Rows[y].Cells[5].Value = Convert.ToDecimal(dsInvoice.Parts.Rows[x]["Price"].ToString()); }

      D Offline
      D Offline
      Dr Walt Fair PE
      wrote on last edited by
      #2

      kruegersck wrote:

      The problem I am having is that when I click on the second or third combobox it executes the item_SelectedIndexChanged event as shown below.

      I'm not sure what you mean. Is the problem that it is supposed to execute that routine and does something you don't want, or that you want it to execute something else? If you want it to do something else, we need to know what you are trying to do. If you don't want it to execute that routine, then remove it from the events or use a different routine.

      CQ de W5ALT

      Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

      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