DataGridView在C#.net中选择了行数据到文本框 [英] DataGridView selected row data to textbox in C#.net

查看:67
本文介绍了DataGridView在C#.net中选择了行数据到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个包含5列的DataGridView。我的要求是,当我在网格中选择一行并单击按钮(发送)时,我需要将第3列中的值放入文本框中,该列包含数据类型字符串的数据。任何人都可以尽快帮助我。

先谢谢。



Anish

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

推荐答案

试试这个.. ................



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

on
dataGridView1_CellDoubleClick
Textbox1.text = dataGridView1[e.ColumnIndex, e.RowIndex].Value;


dataGridView1.CurrentRow.Cells[0].Value





它将为您提供所选行的0. cell的值。


试试这个一个...



您想要选择要发送数据的行,然后单击发送按钮并发送数据?对吧?



所以你可以做这样的事情..



for dataConridview add的dataConridClick事件这段代码(确保在事件之外声明
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
int RowNo;

然后你可以从按钮点击事件)



outside the event..then you can refer it from the button click event)

RowNo = e.RowIndex;




按钮点击活动






for the button click event

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





而不是给单元格[2]你可以给出你在 <里面给出的列名b>




快乐编码......



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

Happy coding....


这篇关于DataGridView在C#.net中选择了行数据到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆