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. Get the underlying combo of a datagridviewcomboboxcolumn

Get the underlying combo of a datagridviewcomboboxcolumn

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 2 Posters 1 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.
  • B Offline
    B Offline
    baranils
    wrote on last edited by
    #1

    Hello I'm trying to acceed the combobox property of a datagridview combobox column I can do it using the EditingControlShowing event

    // \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
    private void DgvKeys\_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
      if (noEvent)
      {
        return;
      }
    
      ComboBox combo = e.Control as ComboBox;
    }
    

    But I need to acceed directly any combo in some column without having to waint an event on it ! To set the combo selected intex for example I was trying this but it does not work !

        DataGridViewComboBoxColumn cby;
        cby = (DataGridViewComboBoxColumn)DgvKeys.Columns\["Region"\];
        cby.SelectedIndex = cby.FindStringExact(combo.Text);
    

    Any idea ?

    H 1 Reply Last reply
    0
    • B baranils

      Hello I'm trying to acceed the combobox property of a datagridview combobox column I can do it using the EditingControlShowing event

      // \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
      private void DgvKeys\_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
      {
        if (noEvent)
        {
          return;
        }
      
        ComboBox combo = e.Control as ComboBox;
      }
      

      But I need to acceed directly any combo in some column without having to waint an event on it ! To set the combo selected intex for example I was trying this but it does not work !

          DataGridViewComboBoxColumn cby;
          cby = (DataGridViewComboBoxColumn)DgvKeys.Columns\["Region"\];
          cby.SelectedIndex = cby.FindStringExact(combo.Text);
      

      Any idea ?

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      baranils wrote:

      I was trying this but it does not work !

      Can you describe in more detail the circumstances when you would want to do this?

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      B 1 Reply Last reply
      0
      • H Henry Minute

        baranils wrote:

        I was trying this but it does not work !

        Can you describe in more detail the circumstances when you would want to do this?

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        B Offline
        B Offline
        baranils
        wrote on last edited by
        #3

        Thank you Henry "Can you describe in more detail the circumstances when you would want to do this?" Good question ! I have three combobox column on single row (one and only one) Those three combo are binded to three different tables There is a logical relation berween those tables If the user select a value in the third combo I want to show the related value in the first and second cell So I'm trying to force the values of two cell but it doesn't work I'm trying this If I change the appellation Column Pays must shows "France" And Region must Show "Bordeaux" But Pays remain empty !! I thought it was because I also have to change the selected item of the combo ??

        // \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
        private void DgvKeys\_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
          if (noEvent)
          {
            return;
          }
        
          ComboBox combo = e.Control as ComboBox;
          if (combo != null)
          {
        
            combo.DropDownStyle = ComboBoxStyle.DropDown;
            combo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            combo.AutoCompleteSource = AutoCompleteSource.ListItems;
        
            combo.SelectedIndexChanged -= new EventHandler(ComboBox\_SelectedIndexChanged);
            combo.SelectedIndexChanged += new EventHandler(ComboBox\_SelectedIndexChanged);
          }
        }
        
        // \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
        private void ComboBox\_SelectedIndexChanged(object sender, EventArgs e)
        {
          noEvent = true;
          ComboBox combo = (ComboBox)sender;
        
          if (combo.SelectedItem == null)
          {
            return;
          }
        
          DataRowView cRowV = (DataRowView)combo.SelectedItem;
          DataRow cRow = cRowV.Row;
        
        
          if (combo.DisplayMember == "Appellation")
          {
            DgvKeys.Rows\[0\].Cells\["Pays"\].Value = "France"; // = GetPaysName(cRow\["PaysID"\]);
            DgvKeys.Rows\[0\].Cells\["Region"\].Value = "Bordeaux"; // GetRegionName(cRow\["RegionID"\]);
            curApel = cRow\["Appellation"\].ToString();
            curApelID = Tools.GetInt(cRow\["ApelID"\]);
            noEvent = false;
            return;
          }
        }
        
        B 1 Reply Last reply
        0
        • B baranils

          Thank you Henry "Can you describe in more detail the circumstances when you would want to do this?" Good question ! I have three combobox column on single row (one and only one) Those three combo are binded to three different tables There is a logical relation berween those tables If the user select a value in the third combo I want to show the related value in the first and second cell So I'm trying to force the values of two cell but it doesn't work I'm trying this If I change the appellation Column Pays must shows "France" And Region must Show "Bordeaux" But Pays remain empty !! I thought it was because I also have to change the selected item of the combo ??

          // \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
          private void DgvKeys\_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
          {
            if (noEvent)
            {
              return;
            }
          
            ComboBox combo = e.Control as ComboBox;
            if (combo != null)
            {
          
              combo.DropDownStyle = ComboBoxStyle.DropDown;
              combo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
              combo.AutoCompleteSource = AutoCompleteSource.ListItems;
          
              combo.SelectedIndexChanged -= new EventHandler(ComboBox\_SelectedIndexChanged);
              combo.SelectedIndexChanged += new EventHandler(ComboBox\_SelectedIndexChanged);
            }
          }
          
          // \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
          private void ComboBox\_SelectedIndexChanged(object sender, EventArgs e)
          {
            noEvent = true;
            ComboBox combo = (ComboBox)sender;
          
            if (combo.SelectedItem == null)
            {
              return;
            }
          
            DataRowView cRowV = (DataRowView)combo.SelectedItem;
            DataRow cRow = cRowV.Row;
          
          
            if (combo.DisplayMember == "Appellation")
            {
              DgvKeys.Rows\[0\].Cells\["Pays"\].Value = "France"; // = GetPaysName(cRow\["PaysID"\]);
              DgvKeys.Rows\[0\].Cells\["Region"\].Value = "Bordeaux"; // GetRegionName(cRow\["RegionID"\]);
              curApel = cRow\["Appellation"\].ToString();
              curApelID = Tools.GetInt(cRow\["ApelID"\]);
              noEvent = false;
              return;
            }
          }
          
          B Offline
          B Offline
          baranils
          wrote on last edited by
          #4

          Hello ! I've just finded out that a part of the problem seems to come because I've defined a Value Member to my ComboboxColumn If I remove the assignation of the valuemember I can force the value of the cell without problem ???

          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