Can I put the focus in a row of my gridview according to the code?

0
Dim dt As New DataTable
Dim sql As String = "SELECT IdProd, Nombre, Precio FROM RE_ProdServ WHERE Codigo =" & lblCodProd.Text
dt = SMT_AbrirTabla(Conexion, sql)
Dim id As Integer
id = Convert.ToInt16(dt.Rows.Item(0).Item(0))

  If id = Convert.ToInt16(SelProductos.VistaProdSeleccionados.GetRowCellValue(i, "IdProd")) Then

  'Aqui seria donde pone el foco'

  End If
    
asked by avargasma 12.05.2016 в 18:34
source

2 answers

1

The row can be set with the FocusedRowHandle property and the column with the FocusedColumn property. Then you just have to call the ShowEditor () method to start editing the cell.

SelProductos.VistaProdSeleccionados.FocusedRowHandle = i
SelProductos.VistaProdSeleccionados.FocusedColumn = SelProductos.VistaProdSeleccionados.Columns("IdProd")
SelProductos.VistaProdSeleccionados.ShowEditor()
    
answered by 12.05.2016 в 22:21
0

You could implement with the help of linq

Dim row As DataGridViewRow = VistaProdSeleccionados.Rows.Cast(Of DataGridViewRow).FirstOrDefault(Function(x) Convert.ToInt32(x.Cells("IdProd").Value) == id)

If row IsNot Nothing Then
   row.Selected = true
End If

This way you look in the IdProd column and if some match the id you will select it

    
answered by 12.05.2016 в 19:02