How to retrieve data from a DataGridView row

Solved
sihem hcine Posted messages 133 Status Member -  
 Anonymous user -
Good evening,
I want to retrieve the data from the selected row of the datagridview into textboxes,
I manage to retrieve only the data from the first row
here is my code:

 dim rownum as integer If rownum > dtt.Rows.Count - 1 Then MsgBox("table vide") Me.txtnom.Focus() Else 'display data in the textboxes Me.txtref.Text = dtt.Rows(rownum).Item("Mat_ben") Me.txtnom.Text = dtt.Rows(rownum).Item("Nom_ben") Me.txtprenom.Text = dtt.Rows(rownum).Item("Pren_ben") Me.txtadr.Text = dtt.Rows(rownum).Item("Adr_ben") Me.txttel.Text = dtt.Rows(rownum).Item("Tel_ben") Me.txtemail.Text = dtt.Rows(rownum).Item("Email") Me.txtst.Text = dtt.Rows(rownum).Item("Statut") Me.txtinsc.Text = dtt.Rows(rownum).Item("Date_insc") Me.txtnaiss.Text = dtt.Rows(rownum).Item("Date_naiss") 'display data in the datagrid DataGrid1.SetDataBinding(dts, "benevole") btnenr.Enabled = False End If 


I 'try to add a foreach loop but I got stuck on the type of the counter ,
Thanks for helping me

EDIT: Language precision in syntax highlighting.

1 answer

  1. Anonymous user
     
    Hello,
    Binding would allow you, starting from a list of objects whose properties correspond to the grid columns, to display those you want in any control.

    See here
    https://codes-sources.commentcamarche.net/faq/1291-utilisation-du-binding-au-travers-de-l-objet-databindingsource

    --
    Moderation brings me to intervene in many posts, but the only languages I know are C# and a bit of VB. For your code, remember to colorize syntax.
    Answer found -> Question Solved
    0
    1. Anonymous user
       
      By the way I corrected the syntax highlighting for you
      0
    2. sihem hcine Posted messages 133 Status Member
       
      thank you for your attention, but I will fill the fields using the code rather than from the datasource property
      0
    3. Anonymous user
       
      Oh well. If you prefer not to use the tools, practices, developed exactly for your need.....
      0