Based on what I could understand about your question, I offer you an alternative solution:
Regarding this I can not select with the checkbox the first thing you should check is the following:
Your DataGridView
must have the editing option enabled, also verify that the column you want to be editable in this case type checkbox
has the property ReadOnly
established in false
:
Then, assuming you're going to save the data once you see the Botón Guardar
:
DataSet dataset = new DataSet();
private void btn_guardar_Click(object sender, EventArgs e)
{
dataset.Tables[0].Columns.Add("folioOrden", typeof(string));
dataset.Tables[0].Columns.Add("tipoMovimiento", typeof(string));
dataset.Tables[0].Columns.Add("producto", typeof(string));
dataset.Tables[0].Columns.Add("observaciones", typeof(string));
dataset.Tables[0].Columns.Add("pesoNeto", typeof(double)); //o decimal
dataset.Tables[0].Columns.Add("idRecepcionesPerga", typeof(int));
dataset.Tables[0].Columns.Add("idProveedor", typeof(int));
dataset.Tables[0].Columns.Add("idContrato", typeof(int));
dataset.Tables[0].Columns.Add("kilogramos", typeof(double));
foreach (DataGridViewRow row in dataGridView1_BuscarProductor.Rows)
{
if (Convert.ToBoolean(dataGridView1_BuscarProductor.Rows[row.Index].Cells[0].Value) == true) //True (Seleccionado)
{
var filas = dataset.Tables[0].NewRow();
//LLenando las filas
filas["folioOrden"] = tuTextBoxFolio.text;
filas["tipoMovimiento"] = tuTextBoxTipoMov.text;
filas["producto"] = tuTextBoxProducto.text;
filas["observaciones"] = tuTextBoxObservaciones.text;
filas["pesoNeto"] = Convert.ToDouble(tuTextBoxPesoNeto.text);
filas["idRecepcionesPerga"] = Convert.ToInt16(dataGridView1_BuscarProductor.Rows[row.Index].Cells[1].Value);
filas["idProveedor"] = Convert.ToInt16(dataGridView1_BuscarProductor.Rows[row.Index].Cells[2].Value);
filas["idContrato"] = Convert.ToInt16(dataGridView1_BuscarProductor.Rows[row.Index].Cells[3].Value);
filas["kilogramos"] = Convert.ToDouble(dataGridView1_BuscarProductor.Rows[row.Index].Cells[4].Value);
//Agrega las filas al dataset.
dataset.Tables[0].Rows.Add(filas);
}
}
///Luego cuando vallas a guardar los datos a tu base de datos
///recorres el 'dataset' e inserta todos los datos que contenga en la Base de Datos..
for (int i = 0; i < dataset.Tables[0].Rows.Count; i++)
{
//Insertas los valores a la BD.....
}
}
I explain the operation:
-
1st. A dataset
is created and you add the corresponding columns to each textbox
and column of your 'datagridview.
-
2nd. You scroll the datagridview
and for each selected row, you assign the values to dataset
.
-
3rd. You scroll the dataset
and insert that data in your Database in the way you are doing, that depends on you.
I hope it helps you!