Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi all,

I have one DataGridView with 5 columns. My requirement is that, when i select a row in grid and click on button(send)I need the value in the 3rd column in to a text box and the column contain data of data type string. Anyone could help me ASAP.
Thanks in Advance.

Anish
Posted
Updated 27-Sep-17 23:13pm
v2

try this..................

on
dataGridView1_CellDoubleClick
Textbox1.text = dataGridView1[e.ColumnIndex, e.RowIndex].Value;
 
Share this answer
 
v2
Comments
Anish612 21-Nov-12 4:43am    
Thanks for the quick solution
Member 10738387 5-Jun-19 2:14am    
is there any way to assign data to another form's textbox. if doubleclick event happens, new form should open with values in the textbox
dataGridView1.CurrentRow.Cells[0].Value


it will give you value of selected row's 0. cell.
 
Share this answer
 
v3
Comments
Anish612 21-Nov-12 4:41am    
That make sense. Thanks for your time
Member 13639193 7-May-19 18:14pm    
Thanks it worked for me
try this one...

you want to fist select the row you want to send data and then click the "Send" button and send data? right?

so you can do something like this..

for the CellContentClick event of datagridview add this code (make sure to declare
C#
int RowNo;
outside the event..then you can refer it from the button click event)

C#
RowNo = e.RowIndex;


for the button click event

C#
string Value = dataGridView1.Rows[RowNo].Cells[2].Value.ToString();


instead of giving Cells[2] you can give column name that you have given inside " "

Happy coding....
 
Share this answer
 
Comments
Anish612 21-Nov-12 4:42am    
Thanks for the effort
if(datagridview1.SelectedRows.Count > 0)
{
textBox1.Text = datagridview1.SelectedRows[0].Cells[1].Value.ToString();
}
 
Share this answer
 
Comments
Graeme_Grant 28-Sep-17 5:51am    
WHY are you answering a 5-YEAR-OLD question that has ALREADY ACCEPTED answers??? Please don't, instead focus on current question ONLY - there are always plenty waiting for help.

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