How to retrieve data from a DataGridView row
Solved
sihem hcine
Posted messages
133
Status
Member
-
Anonymous user -
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:
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.
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
-
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