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. Manually add data to datagrid combobox in C#

Manually add data to datagrid combobox in C#

Scheduled Pinned Locked Moved C#
csharphelpquestion
5 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.
  • B Offline
    B Offline
    Brad Wick
    wrote on last edited by
    #1

    I am trying to fill a combobox that is in a datagrid with values. The code compiles fine, but when it generates the datagrid it gives a error. "System.ArgumentException: DataGridViewComboBoxCell value is not valid". Any ideas what I am doing wrong? DataGridViewComboBoxCell colComboCell = new DataGridViewComboBoxCell(); colComboCell.Items.Add("0"); colComboCell.Items.Add("1"); colComboCell.Items.Add("2"); colComboCell.Items.Add("3"); dataGridTicketTypes.Rows.Add(EventTicketPrice_ID, colComboCell);

    S 1 Reply Last reply
    0
    • B Brad Wick

      I am trying to fill a combobox that is in a datagrid with values. The code compiles fine, but when it generates the datagrid it gives a error. "System.ArgumentException: DataGridViewComboBoxCell value is not valid". Any ideas what I am doing wrong? DataGridViewComboBoxCell colComboCell = new DataGridViewComboBoxCell(); colComboCell.Items.Add("0"); colComboCell.Items.Add("1"); colComboCell.Items.Add("2"); colComboCell.Items.Add("3"); dataGridTicketTypes.Rows.Add(EventTicketPrice_ID, colComboCell);

      S Offline
      S Offline
      Sami Sammour
      wrote on last edited by
      #2

      You can try the following code assuming that the comboBox column is named valueColumn: DataGridViewColumn valueColumn = new DataGridViewColumn(); dataGridTicketTypes.Columns.Add( valueColumn ); DataGridViewRow row = new DataGridViewRow(); DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell(); cell.Items.Add("0"); cell.Items.Add("1"); cell.Items.Add("2"); cell.Items.Add("3"); valueColumn.CellTemplate = cell; int rowIndex = dataGridTicketTypes.Rows.Add( row ); row = dataGridTicketTypes.Rows[ rowIndex ]; Hope it helps. If you have any question contact me. :)

      B 1 Reply Last reply
      0
      • S Sami Sammour

        You can try the following code assuming that the comboBox column is named valueColumn: DataGridViewColumn valueColumn = new DataGridViewColumn(); dataGridTicketTypes.Columns.Add( valueColumn ); DataGridViewRow row = new DataGridViewRow(); DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell(); cell.Items.Add("0"); cell.Items.Add("1"); cell.Items.Add("2"); cell.Items.Add("3"); valueColumn.CellTemplate = cell; int rowIndex = dataGridTicketTypes.Rows.Add( row ); row = dataGridTicketTypes.Rows[ rowIndex ]; Hope it helps. If you have any question contact me. :)

        B Offline
        B Offline
        Brad Wick
        wrote on last edited by
        #3

        The code you provided did add the items to a dropdown menu, however it added a new column in which it added this data which I want to specify it as I am adding values. 1. Create a new form 2. Add a datagridview1 to the form 3. add two columns to the data grid (IDColumn, valueColumn) 4. Add a button to the form which will insert a record 5. When you click on the button it should add one row to the DataGrid by using something like below (but that actually works).

        DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
        cell.Items.Add("0");
        cell.Items.Add("1");
        cell.Items.Add("2");
        cell.Items.Add("3");
        dataGridView1.Rows.Add("test", cell);

        S 1 Reply Last reply
        0
        • B Brad Wick

          The code you provided did add the items to a dropdown menu, however it added a new column in which it added this data which I want to specify it as I am adding values. 1. Create a new form 2. Add a datagridview1 to the form 3. add two columns to the data grid (IDColumn, valueColumn) 4. Add a button to the form which will insert a record 5. When you click on the button it should add one row to the DataGrid by using something like below (but that actually works).

          DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
          cell.Items.Add("0");
          cell.Items.Add("1");
          cell.Items.Add("2");
          cell.Items.Add("3");
          dataGridView1.Rows.Add("test", cell);

          S Offline
          S Offline
          Sami Sammour
          wrote on last edited by
          #4

          You can skip the first two lines : DataGridViewColumn valueColumn = new DataGridViewColumn(); dataGridTicketTypes.Columns.Add( valueColumn );

          B 1 Reply Last reply
          0
          • S Sami Sammour

            You can skip the first two lines : DataGridViewColumn valueColumn = new DataGridViewColumn(); dataGridTicketTypes.Columns.Add( valueColumn );

            B Offline
            B Offline
            Brad Wick
            wrote on last edited by
            #5

            I already had those skipped. My code looks like this which still does not add information to the drop down menu. private void button1_Click(object sender, EventArgs e) { DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell(); cell.Items.Add("0"); cell.Items.Add("1"); cell.Items.Add("2"); cell.Items.Add("3"); dataGridView1.Rows.Add("test", cell); }

            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