?
Solved

datagrid cell selection

Posted on 2004-11-13
14
Medium Priority
?
361 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:Prof_MAM
  • 7
  • 6
14 Comments
 
LVL 8

Expert Comment

by:gajender_99
ID: 12578000
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
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12582499
Just bind the textboxes to the same datasource as the datagrid, then there is no extra coding needed, it will navigate automatically
0
 

Author Comment

by:Prof_MAM
ID: 12591085
how to bind datagrid and the text box to datasource
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 80 total points
ID: 12591778
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
 

Author Comment

by:Prof_MAM
ID: 12592285
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
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12592292
What is the error  you are getting (because the type doesn't matter)
0
 

Author Comment

by:Prof_MAM
ID: 12593089
str_var.databindings  is underlined by blue  
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12593195
Than it doesn't understand str_var , what should str_var be ? The name of your textbox ?
0
 

Author Comment

by:Prof_MAM
ID: 12593394
no no, it is a  string variable.
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12593457
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
 

Author Comment

by:Prof_MAM
ID: 12593531
Sorry but I changed one of The 3 textbox by A string Variable .
So there is no solution ?
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12593594
Yes there always is a solution, but what are you trying to achieve exactly.
0
 

Author Comment

by:Prof_MAM
ID: 12593631
Ok that will be In anothor Question .
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question