Buen día, gracias de antemano por su ayuda
Tengo una tabla con codigo, clave, descripcion, precio
y tengo un formulario y busco desde un textbox la clave y me trae los datos a los texbox
me trae codigo, descripcion,precio y tengo otros textbox donde tecleo cantidad y descuento
al insertar descuento y cantidad el boton ingresar me hace el calculo de total precio*cantidad-descuento y lo inserto en un datagridview
y ahí sigo insertando mas datos.
Mi problema es que seleciono una fila del datagidview y me pasa los datos de la fila a los texbox
Estos quiero modificarlos por jemplo para cambiar la cantidad o el descuento,precio y que los modifique en la misma fila del datagridview
Tengo este código al seleccionar la fila en el datagrid me pasa los datos a los textbox
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick, DataGridView1.CellClick
'al seleccionar una fila manda los datos a los texbox
Dim i As Integer
i = DataGridView1.CurrentRow.Index
txtcantidad.Text = DataGridView1.Item(0, i).Value()
txtclave.Text = DataGridView1.Item(1, i).Value()
txtdescripcion.Text = DataGridView1.Item(2, i).Value()
txtlista.Text = DataGridView1.Item(3, i).Value()
txtprecio.Text = DataGridView1.Item(4, i).Value()
txtdescuento.Text = DataGridView1.Item(5, i).Value()
txttotal.Text = DataGridView1.Item(6, i).Value()
End Sub
y este es el codigo para insertar los datos que busco de la base de datos
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btinsertar.Click
If txtclave.Text = "" Then 'SI EL TEXBOX DE CODIGO ESTA VACIO QUE MANDE MENSAJE Y NO INGRESE NADA AL DATAGRID
MsgBox("DEVE INGRESAR CODIGO")
txtclave.Select() 'ASIGNA EL FOCUS AL TXT CODIGO
Else
row(0) = txtcantidad.Text
row(1) = txtclave.Text
row(2) = txtdescripcion.Text
row(3) = txtlista.Text
row(4) = txtprecio.Text
row(5) = txtdescuento.Text
row(6) = Val(txtcantidad.Text) * Val(txtprecio.Text) 'INSERTA LA MULTIPLICACION DEL PRECIO UNITARIO Y LA CANTIDAD
Dim rowToSave As String() = New String() {row(1), row(2), row(3), row(4), row(5), row(6)}
DataGridView1.Rows.Add(row)
txtcantidad.Text = ""
txtclave.Text = ""
txtdescripcion.Text = ""
txtprecio.Text = ""
txtdescuento.Text = ""
txtlista.Text = ""
txttotal.Text = ""
End If
'PARA SUMAR LA COLUMNA DE TOTALES
Dim Total As Single
Dim cont As Integer = 0 'PARA CONTADOR DE PARTIDAS
Dim Col As Integer = Me.DataGridView1.CurrentCell.ColumnIndex
For Each row As DataGridViewRow In Me.DataGridView1.Rows
Total += Val(row.Cells(6).Value) 'ROW.CELLS (NUMERO DE LA COLUMNA A SUMAR).VALUE
Next
Me.txttotalgral.Text = Total.ToString
'PARA CONTAR EL NUMERO DE PARTIDAS
For Each r As DataGridViewRow In DataGridView1.Rows
'en cells() va el indice de la columna que quiere verificar que tenga datos
If Not r.Cells(0).Value = "" Then
cont += 1
End If
Next
' MsgBox("las filas con registros son: " & cont)
txtpartidas.Text = cont 'PASA EL DATO A UN TEXBOX
End Sub
Espero me puedan orientar con este detalle gracias