Click here to Skip to main content
15,909,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

I would like to ask, how to display selected item from datagrid to textbox? I'm using vb.net. I thought the codes for winform and wpf are the same...

i tried using this code:

VB
Private Sub dgv_admin_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs) Handles dgv_admin.MouseLeftButtonDown


Dim i As Integer
       i = dgstudents.CurrentRow.Index

       Lblid.Text = dgstudents.Item(0, i).Value
       TxtLname.Text = dgstudents.Item(1, i).Value
       TxtFname.Text = dgstudents.Item(2, i).Value


   End Sub


but nothing is seen on the textboxes.
Posted
Updated 29-Aug-13 23:00pm
v2
Comments
Pheonyx 30-Aug-13 4:16am    
If you are doing this in WPF, why not just use databinding in the XAML to associate it?
hoyice 30-Aug-13 4:43am    
i am doing my interface to expression blend and i code in vb.net because my data is from SQL. I am not familiar with view model.

1 solution

Like Pheonyx mentioned, create viewModel, with some property, which will be binding to your view. When you would like to show data in textbox, just set created property to your value like :
C#
createdProperty = dgstudents.Item(1, i).Value

and via binding it will be shown in your view.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900