Okay so I have a datagrid view I am trying to build (here is the code so far)

public partial class employeeAlterForm4 : Form
    static readInFileDel2 readInFileCall = new readInFileDel2(readInFileClass2.readInFile2);
    static Employee [] employeeTempArray;
    ToolTip tooltip1 = new ToolTip();
    Panel panel1 = new Panel();
    public employeeAlterForm4()

      bool supHold = false;

      employeeShiftType [] shiftType = new employeeShiftType [1];
      DataGridViewComboBoxCell shiftComboBox = new DataGridViewComboBoxCell();

      dataGridView1.ColumnCount = 4;
      dataGridView1.Columns [0].Name = "Employee Name";
      dataGridView1.Columns [1].Name = "Age *";
      dataGridView1.Columns [2].Name = "Position";
      dataGridView1.Columns [3].Name = "Shift Types";

      for (int i = 0; i < employeeTempArray.Length - 1; i++)
        dataGridView1 [0, i].Value = employeeTempArray [i].isName();

        dataGridView1 [1, i].Value = employeeTempArray [i].isAge();

        supHold = employeeTempArray [i].isSup();
        if (supHold == true)
          dataGridView1 [2, i].Value = "Supervisor";
          dataGridView1 [2, i].Value = "Employee";
        shiftType = employeeTempArray [i].isShiftType();       

        //I want to add a comboBox here on column 3 (the one you see abot that is labeled
        //"Shift Type"

      DataGridViewColumn column = dataGridView1.Columns[0];
      column.Width = 150;

I have tried to code it like this (see this screen to give you as well for an idea)

dataGridView1 [3, i] = shiftComboBox;

But it only works for the first row, when i increments to 2 I get an error code that says "Cell provided already belongs to a grid. This operation is not valid." Why can't i seem to add another row.

But here is what weird when it's [3, 0] it displays it on the first row, but if it's [3, 1] it displays it on the last line (the blank one you see in the screen) no matter what size. I just can't figure out why this won't work

Try to use DataGridViewComboBoxColumn instead. You could find example from help about that method.

Well I mean how do I use it the only time I got it to suceed i had like 4 added to each row, and they didn't do under the row "Shift Type"

nevermind solved it myself

DataGridViewComboBoxCell shiftComboBox = new DataGridViewComboBoxCell();
dataGridView1 [3, i] = shiftComboBox;

I had to declare shiftComboBox in the for loop so it was created each time, this seems to have fixed the problem (still need to insert items in the combo box to truly test it out)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.