Link to home
Start Free TrialLog in
Avatar of Prof_MAM
Prof_MAM

asked on

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.
Avatar of gajender_99
gajender_99

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
Just bind the textboxes to the same datasource as the datagrid, then there is no extra coding needed, it will navigate automatically
Avatar of Prof_MAM

ASKER

how to bind datagrid and the text box to datasource
ASKER CERTIFIED SOLUTION
Avatar of RonaldBiemans
RonaldBiemans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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") .
What is the error  you are getting (because the type doesn't matter)
str_var.databindings  is underlined by blue  
Than it doesn't understand str_var , what should str_var be ? The name of your textbox ?
no no, it is a  string variable.
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
Sorry but I changed one of The 3 textbox by A string Variable .
So there is no solution ?
Yes there always is a solution, but what are you trying to achieve exactly.
Ok that will be In anothor Question .