473,396 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Get data from Datagrid into textboxes

First of all, i'm a newbie to winforms :)

I have created a dataset with data from my DB and using that as my datasource for my gridview, a little bit of code:

Expand|Select|Wrap|Line Numbers
  1. // Define Connection string
  2.             string DB_ConnStr = ConfigurationManager.ConnectionStrings["SupportTool.Properties.Settings.DB_Contact_ConnStr"].ConnectionString;
  3.  
  4.             // Define SQL Connection
  5.             SqlConnection DB_Conn = new SqlConnection(DB_ConnStr);
  6.  
  7.             // Define SQL Command from Stored Procedure
  8.             SqlCommand cmd = new SqlCommand("GetAllContactPerson", DB_Conn);
  9.             cmd.CommandType = CommandType.StoredProcedure;
  10.  
  11.             // Create DataAdapter
  12.             SqlDataAdapter daContactPerson = new SqlDataAdapter();
  13.             daContactPerson.SelectCommand = cmd;
  14.  
  15.             // Create DataSet + DataTable
  16.             DataSet dsContactPerson = new DataSet();
  17.             DataTable dtContactPerson = new DataTable();
  18.  
  19.             // Fill DataSet and DataTable with Data from DataAdapter
  20.             daContactPerson.Fill(dsContactPerson);
  21.             daContactPerson.Fill(dtContactPerson);
  22.  
  23.             // set Datagrid's datasource to use DataSet
  24.             gvwContactPerson.DataSource = dsContactPerson.Tables[0].DefaultView;
  25.  
  26.  
  27.  
What I am basically trying to do is, when I click some where in the grid, it should take the data from that specific row and put it into my textboxes, but i'm lost.

I have a column which holds an unique ID for each row.

Any help is appreciated.


/ Bonx666
Jan 7 '10 #1
1 3202
Frinavale
9,735 Expert Mod 8TB
Implement a method that handles the CellClick event or the CellContentClick event.

You can retrieve which row was clicked on from the DataGridViewCellEventArgs argument passed into the method.

-Frinny
Jan 7 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: sandman | last post by:
I've got a simple windows form with some bound textboxes and Save button. Each texbox is bound to column in a table in an Access database. The form fills fine - all the fields show the correct...
2
by: crocketo | last post by:
Hi, I've made a winform with several labels, textboxes and a datagrid. My question is: How do I, when a row in the datagrid is clicked, retrieve that data? Let's say I've got a datagrid with...
2
by: Josef Meile | last post by:
Hi, I'm using a ComboBox, some Textboxes, and a DataGrid to represent a many-to-many relationship between Person and Course. Each time that I change the value in the ComboBox (which for now is...
12
by: Mike | last post by:
I'm calling a component to get my data. The component is returning a dataset. I need to populate text boxes on my aspx page with the data within the datalist. Where can I find an example that...
2
by: alpoor | last post by:
I have lots of textboxes on my webform. I need to bind them with fields from table. I am not sure how to bind with textboxes. I have seen so many samples for dropdown boxes and datagrid binding,...
6
by: needin4mation | last post by:
I have a set of textboxes. If it is a new record the textboxes are empty and there is a save button. If this is an existing record, I have a search form, a datagrid and the user selects form the...
1
by: hcs | last post by:
Hello, on a datagrid when you alter the dataset and want to show the new dataset you use datagrid.refresh(). how is this possible on a form which is based on a dataset and consists of a number...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
1
by: geeteshss | last post by:
Dear all, actually i spent a whole month on the R&D of datagrid edit ,update,cancel events but recently my guide told me to make it user friendly because no user would like to go on searching rows...
5
by: Kolags | last post by:
Hi all, Please give me guidance to complete this task. As per my requirement, I want to place data in to different textboxes whatever I selected from datagrid using edit command name. Means I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.