datagrid cell selection

I have   datagrid contian 3 fields from database table  and 3 textbox ,what I want is a code to make the  the 3 textbox show the datagrid field depending on selected row from datagrid .  when clicking on any cell of the dtagrid the 3 textbox should show content of that row.
Prof_MAMAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gajender_99Commented:
Private Sub datagrid_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles datagrid.Navigate
 Dim r As Integer
  r = datagrid.CurrentCell.RowNumber
        textbox1.text= datagrid.Item(r, 0)  '0 for first column
        textbox2.text= datagrid.Item(r,1)  '1 for second column
        textbox3.text= datagrid.Item(r, 2)  '0 for third column
End Sub


if you require more information just write
0
RonaldBiemansCommented:
Just bind the textboxes to the same datasource as the datagrid, then there is no extra coding needed, it will navigate automatically
0
Prof_MAMAuthor Commented:
how to bind datagrid and the text box to datasource
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

RonaldBiemansCommented:
Lets say you have a dataset called DS, which contains one table with 3 columns (col1,col2,col3)
and you a datagrid (datagrid1) and 3 textboxes (textbox1,textbox2,textbox3)

if you put this in the load event of your form

datagrid.datasource = DS.tables(0)
TextBox1.DataBindings.Add("Text", ds.tables(0), "col1")
TextBox2.DataBindings.Add("Text", ds.tables(0), "col2")
TextBox3.DataBindings.Add("Text", ds.tables(0), "col3")

if you navigate in the datagrid the textboxes should display the correct items



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Prof_MAMAuthor Commented:
that is good , it works corrctly But what If I have String varialble ? Can I bind it also ? Itryed this code but it didn't work
Str_Var.DataBindings.Add("Text", GridDataSet.Tables(0), "Std_ID") .
0
RonaldBiemansCommented:
What is the error  you are getting (because the type doesn't matter)
0
Prof_MAMAuthor Commented:
str_var.databindings  is underlined by blue  
0
RonaldBiemansCommented:
Than it doesn't understand str_var , what should str_var be ? The name of your textbox ?
0
Prof_MAMAuthor Commented:
no no, it is a  string variable.
0
RonaldBiemansCommented:
Well you can't add databindings to any variable. Databinding is used for controls like a textbox or datagrid etc..

you said you wanted to

"what I want is a code to make the  the 3 textbox show the datagrid field depending on selected row from datagrid "

so where does this variable fit in
0
Prof_MAMAuthor Commented:
Sorry but I changed one of The 3 textbox by A string Variable .
So there is no solution ?
0
RonaldBiemansCommented:
Yes there always is a solution, but what are you trying to achieve exactly.
0
Prof_MAMAuthor Commented:
Ok that will be In anothor Question .
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.