Filling txtbox with selected index of datagrid

drpcken

Member
Joined
Jun 15, 2004
Messages
12
Programming Experience
1-3
I have textboxes, and when I select a line of a datagrid, I want to fill the textboxes with the index values of the selected line. I use to have this working, but I made some changes, now its all messed up. Here's some code.

Private Sub dgRecs_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgRecs.SelectedIndexChanged
txtRecId.Text = dgRecs.SelectedIndex.ToString(1)

When I select a line in the datagrid, instead of putting the value of the index (1), it puts the number 1, and 2 for index(2)

Frustrating! Thanks again guys!
 
Are you using c# or VB? silly question but it looks like c# to me.

Anyway try something like this

txtRecId.Text = dgRecs.SelectedItems(0).Text


I think that might work
 
Yay

Just as I got your msg it dawned on me what I was doing wrong.

First of all, its vb.net :)

Here's the answer though, you were really close, and I greatly appreciate your answer.

txtRecId.Text = dgRecs.SelectedItem.Cells(1).Text

:)
Thanks again friend.
 
Back
Top