Foros del Web » Programación para mayores de 30 ;) » .NET »

Datagridview y evento después de actualizar

Estas en el tema de Datagridview y evento después de actualizar en el foro de .NET en Foros del Web. Hola, tengo un datagrid en el cual la primera columna es un combobox. Cuando introduzco una nueva línea, necesito cotejar el valor que se selecciona ...
  #1 (permalink)  
Antiguo 04/04/2009, 10:58
 
Fecha de Ingreso: marzo-2008
Mensajes: 127
Antigüedad: 16 años, 1 mes
Puntos: 1
Datagridview y evento después de actualizar

Hola,
tengo un datagrid en el cual la primera columna es un combobox.
Cuando introduzco una nueva línea, necesito cotejar el valor que se selecciona en el combobox, ya que puede no ser válido, en cuyo caso emitiré un aviso.

Pues eso, que no consigo aislar el evento adecuado para ejecutar la rutina de comprobación.

Tal vez alguien me pueda indicar esto.

Muchas gracias
  #2 (permalink)  
Antiguo 04/04/2009, 11:36
 
Fecha de Ingreso: octubre-2000
Mensajes: 1.692
Antigüedad: 23 años, 6 meses
Puntos: 19
Respuesta: Datagridview y evento después de actualizar

Siempre me pasa eso porque tiene un monton de cosas.
Pero fijate si no es el RowValidating

Aca unos ejemplos que encontre:
Código:
private void dataGridView1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {

            bool bHaveError = false;
            string sErrorMsg_RequiredFields = string.Empty;
            int newInteger;

            if (this.dataGridView1.IsCurrentRowDirty)
            {
                System.Windows.Forms.DataGridViewRow oDGVR = this.dataGridView1.Rows[e.RowIndex];
              
                if (oDGVR.Cells["FirstName"].Value.ToString().Trim().Length < 1)
                {
                    sErrorMsg_RequiredFields += "   First name is required." + Environment.NewLine;
                    bHaveError = true;
                }

                if (oDGVR.Cells["Age"].Value.ToString().Trim().Length < 1)
                {
                    sErrorMsg_RequiredFields += "   Age is required." + Environment.NewLine;
                    bHaveError = true;
                }
                else if (!int.TryParse(oDGVR.Cells["Age"].Value.ToString(), out newInteger) || newInteger < 0)
                {
                    sErrorMsg_RequiredFields += "   Age must be a number." + Environment.NewLine;
                    bHaveError = true;
                }


               if (oDGVR.Cells["IsActive"].Value.ToString() == string.Empty)
                {
                    sErrorMsg_RequiredFields += "   Active Status is required." + Environment.NewLine;
                    bHaveError = true;
                }

                if (bHaveError)
                {
                    oDGVR.ErrorText = sErrorMsg_RequiredFields;
                    e.Cancel = true;
                }
            
            }

        }

        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            int newInteger;

            this.dataGridView1.Rows[e.RowIndex].ErrorText = "";

            // No cell validation for new rows. New rows are validated on Row Validation.
            if (this.dataGridView1.Rows[e.RowIndex].IsNewRow) { return; } 

            if (this.dataGridView1.IsCurrentCellDirty)
            {
                switch (this.dataGridView1.Columns[e.ColumnIndex].Name)
                {
                    case "FirstName":
                        if (e.FormattedValue.ToString().Trim().Length < 1)
                        {
                            e.Cancel = true;
                            this.dataGridView1.Rows[e.RowIndex].ErrorText = "   First name is required.";
                        }
                        break;

                    case "Age":
                        if (e.FormattedValue.ToString().Trim().Length < 1)
                        {
                            e.Cancel = true;
                            this.dataGridView1.Rows[e.RowIndex].ErrorText = "   Age is required.";
                        }
                        else if (!int.TryParse(e.FormattedValue.ToString(), out newInteger) || newInteger < 0)
                        {
                            e.Cancel = true;
                            this.dataGridView1.Rows[e.RowIndex].ErrorText = "   Age must be a positive number.";
                        }
                        break;

                  case "IsActive":
                        if ((CheckState) e.FormattedValue == CheckState.Indeterminate)
                        {
                            e.Cancel = true;
                            this.dataGridViewSection.Rows[e.RowIndex].ErrorText = "   Active status is required.";
                        }
                        break;
                }
            }
        }
Lo saqué de acá:
http://www.forosdelweb.com/newreply....reply&t=686444

Suerte!!!
__________________
PD: Con amor, fe, amor a Dios y amistad podemos hacer un mundo mejor!!!!
  #3 (permalink)  
Antiguo 06/04/2009, 08:37
 
Fecha de Ingreso: marzo-2008
Mensajes: 127
Antigüedad: 16 años, 1 mes
Puntos: 1
Respuesta: Datagridview y evento después de actualizar

Bueno, aunque el ejemplo no se ajusta mucho a lo que quería, si que me ha aportado la idea de "por donde" tirar.


Gracias y un saludo
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:17.