0

I want to have a data gridview that is bounded to SQL data source that has a column with name status also I need this column to be combobox, to be better to the user to select the value instead of writing it, is it possible ? I've searched and I've found this Adding bound combobox to datagridview and it answered how to add comobobox to bounded datagridview, but this is not what I need I've also tried to make another solution in a different way by using menustrip and it works fine but I can't edit the cell value after the user select menusttrip item as the datagridview is bounded to data source

Here is a part of my code related to the 2nd solution:

   dtSamples = cMaster.Select_Samples(nKeyNo, DateTime.Today, strMachine);

   dataGridView_Samples.DataSource = dtSamples;


    //here is the event that shows the menustrip when the user clicked on the desired column 
    private void dataGridView_Samples_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)                                
        {
            DataGridView.HitTestInfo hit = dataGridView_Samples.HitTest(e.X, e.Y);     //Get the clicked cell
            if (e.RowIndex < nNewRowIndex)                                            //If it's a header, ignore
                return;
            dataGridView_Samples.CurrentCell = dataGridView_Samples[e.ColumnIndex, e.RowIndex];    //Select the cell for future info
            StatusRowIndex = e.RowIndex;
            if (dataGridView_Samples.CurrentCell.ColumnIndex == 4)                     //If this is the priority column
            {
                contextMenuStrip_Status.Show(Cursor.Position.X, Cursor.Position.Y); //Show the strip
            }
        }

    }

  //here is the event of selecting item of menustrip and it doesn't show the value in the cell
     private void toolStripMenuItem_Repair_Click(object sender, EventArgs e)
    {
        if (nNewRowIndex == -1)
        {
            dataGridView_Samples.CurrentCell.Value = "Repair";

            dataGridView_Samples.Rows[StatusRowIndex].Cells[4].Value = 4;
            dataGridView_Samples.NotifyCurrentCellDirty(true);
        }

        else
        {
            dataGridView_Samples.Rows[nNewRowIndex].Cells[4].Value = "Repair";
           // dataGridView_Samples.Rows[nNewRowIndex].Cells[4].Value = 4;
            dataGridView_Samples.NotifyCurrentCellDirty(true);
            dataGridView_Samples.BeginEdit(true);
            dataGridView_Samples.EndEdit();
        }

    }
Community
  • 1
  • 1
Sara
  • 86
  • 2
  • 11
  • What is it you are actually trying to accomplish? If this `ComboBoxColumn` is supposed to be one of the data columns returned from SQL, then *why* isn't the linked answer what you need? Or is this `ComboBoxColumn` *not* supposed to be one of the data columns returned from SQL, but an additional column altogether? – OhBeWise Nov 23 '16 at 19:35
  • yes it is supposed to be one of the data columns returned from SQL Regarding the mentioned answer; it is not what I am looking for as it add a new column to the returned SQL table so i will have two columns for the same purpose one is combobox and the other one is normal column – Sara Nov 24 '16 at 08:00

0 Answers0