Ver Mensaje Individual
  #4 (permalink)  
Antiguo 23/01/2009, 16:19
Avatar de Srkuen
Srkuen
 
Fecha de Ingreso: abril-2008
Mensajes: 39
Antigüedad: 16 años, 9 meses
Puntos: 0
Respuesta: LLenar un DataSet

Muchas gracias por tu ayuda, ya me dieron una ayuda para poder resolverlo, esto es lo que me quedo:

Código:
//Función para verificar los campos de los DataGridViewCheckBoxColum y
        //cuantos fueron seleccionados para ser ingresados en la solicitud de envío
        private void BtnAceptar_Click(object sender, EventArgs e)
        {
            //Contador de documentos seleccionados a envíar a custodia
            int m = 0;

            DataTable dataTable = new DataTable();
            //Recorremos las columnas que hay en el DataGridView para copiar la estructura al DataTable.
            foreach (DataGridViewColumn column in this.DGVSeleccionDocumentos.Columns)
            {
                //Como no nos interesa guardar en el DataTable la primera columna,
                //que es la columna que tiene los CheckBox, entonces si el índice es el 0
                //no agregamos la columna al DataTable.
                if (column.Index != 0)
                {
                    dataTable.Columns.Add(column.Name);
                }
            }
            DataGridViewRowCollection gridRowCollection = this.DGVSeleccionDocumentos.Rows;
            //Recorremos las filas que hay en el DataGridView y las copiamos al DataTable.
            foreach (DataGridViewRow gridRow in gridRowCollection)
            {
                DataGridViewCheckBoxCell checkBoxCell = gridRow.Cells[0] as DataGridViewCheckBoxCell;
                if ((checkBoxCell != null) && (checkBoxCell.Value != null) && ((bool)checkBoxCell.Value == true))
                //El usuario ha marcado el CheckBox para la fila que estamos recorriendo.
                {
                    //Agregamos un DataRow al DataTable con los datos que haya a partir de la celda 1.
                    DataRow dataRow = dataTable.Rows.Add(gridRow.Cells[1].Value, gridRow.Cells[2].Value,
                        gridRow.Cells[3].Value, gridRow.Cells[4].Value, gridRow.Cells[5].Value,
                        gridRow.Cells[6].Value, gridRow.Cells[7].Value, gridRow.Cells[8].Value,
                        gridRow.Cells[9].Value, gridRow.Cells[10].Value, gridRow.Cells[11].Value,
                        gridRow.Cells[12].Value, gridRow.Cells[13].Value, gridRow.Cells[14].Value,
                        gridRow.Cells[15].Value, gridRow.Cells[16].Value, gridRow.Cells[17].Value);
                    ++m;
                }
            }
            DataSet ds1 = new DataSet();
            ds1.Tables.Add(dataTable);

            DialogResult dr1 = MessageBox.Show("Se ha seleccionado: \n" + m + " documento(s), " +
                " esta deacuerdo con la selección", "Selección de documentos",
                MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
            if (dr1 == DialogResult.Yes)
            {
                DataSet changes = ds1;
                _dsRowSelected = changes;
                this.Close();
            }
        }
Saludos y que tengas un buen día