My project has a DataGridView
, in frmConsProd
, where the ID column field, receives the prdCod column value from the SQL DB Table.
I need to pass two parameters to second form frmDetailProd
when I click on the Consult button,tsbCons
. The first parameter is the string "Consult", however, I'm having trouble sending the ID column value of the DataGridView
as the second parameter.
Code:
Public Class frmConsProd
Private Sub tsbCons_Click(sender As Object, e As EventArgs) Handles tsbConsult.Click
Try
Using frm As New frmDetailProd("Consult", "datagrid ID value")
frm.txtPrdCod.Enabled = True
frm.txtPrdCod.Text = ""
frm.ShowDialog()
End Using
tsbRefresh.PerformClick()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
End Class
How to get the ID value of my DataGridView
, to be able to send it as a second parameter in the Consult button tsbCons
?
CodePudding user response:
If you are only after one value you can try this:
dim CellValue = yourGrid.Rows(0).Cells(4).value
This example would give you the value of first row, 5th column.
CodePudding user response:
It worked
I created a string and assigned it the value of the datagrid column to be able to pass it as a parameter:
DIM codPrd As String = DataGridView.CurrentRow,Cells("prdCod").Value