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();
}
}