Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Just have a questiion regarding datagridviews and bind data source.

I have a form (FORMA) that has a datagridview with bound data source, when a user clicks on a selected row in the datagrid, i want it to open that selected record in a new form (FORMB)in a detailed view (textbox)

Please could someone outline how this can be complete, as my coding skills are limited.

Thanks
Posted

Hope this might help,


Under DataGridView1_clickCell event add the following codes.

DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
textBox1.Text = row.Cells[0].Value.ToString();
textBox2.Text = row.Cells[1].Value.ToString();

and so on.

This vill populate the text box with the row values that you double clicked in the DataGridView.
 
Share this answer
 
Comments
SIFNOk 30-Mar-11 21:17pm    
Hey

Thanks for your reply harsha :) that information was very usesful, but i was wondering how to open the datagridview in a new form in a textbox view. i want to be able to edit, update changes from this new form....if you are able to point me in the right direction much appreciate it.

Thanks

Sid
ZeeroC00l 31-Mar-11 1:51am    
Well if i got your question right, On button click you want to open a new form with a data grid in it which will populate the text box and then you want to edit those details in the new form.

For doing that, in most simple way, create a new form insert the data grid controller and put the necessary text box items and use the above mentioned code segment method to populate the text box in them. All you need to do is to make that form visible on button click and then the rest can be handled in the new form itself just like you did in this form.
SIFNOk 7-Apr-11 23:01pm    
HiClose i understand what your asying, but on little issue is i dont want a datagrid to be display on the new form, on the new form i only want the textbox of the selected value in the previous which would contain the datagrid.
When you click the button click i want it to open only textboxs on the new form(Form-B)......with the values from the datagrid on the previous form (form-A)
ZeeroC00l 8-Apr-11 0:58am    
You can use the same method as mentioned above along with the form name to set the values.
If you want the selected datagrid value of one form to be displayed in another, initialise the selected values into string variables and then assign them to the text box on button click event along with the form name.
Dalek Dave 10-Apr-11 19:06pm    
Good Answer
easy way for beginers
Under <code>DataGridView1_clickCell</code> event add the following codes.
<pre>DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
dim form2 as new form
form2.show()
form2.textbox1.text="row.Cells[1].Value.ToString();"
form2.textbox1.text= "row.Cells[1].Value.ToString();"
</pre>
 
Share this answer
 
Comments
Dalek Dave 10-Apr-11 19:06pm    
Good Call

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900