如何在c#中从datagridview获取值到文本框 [英] how to get the value from datagridview to textbox in c#

查看:476
本文介绍了如何在c#中从datagridview获取值到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#中将datagridview的值传递给textbox?

我是c#的初学者..我很难找到这个错误的代码..需要帮助!! !!

解决方案

从DataGridView的一个单元格中检索文本:

展开 | 选择 | Wrap | 行号

...如果我想选择整行,而不仅仅是当前单元格怎么办?

我会把你的代码放在datagridview方法的currentcellcontent上吗?


您可以选择当前单元格,例如点击它 - 通过订阅这4个事件中的一个(选择最适合你的事件):


- CellClicked http://msdn.microsoft.com/ en-us / libr ... cellclick.aspx

- CellContentClick http://msdn.microsoft.com/en-us/libr...tentclick.aspx

- CellContentDoubleClicked http://msdn.microsoft.com/en-us/libr...ubleclick.aspx

- CellDoubleClicked http: // MSDN。 microsoft.com/en-us/libr...ubleclick.aspx


或者您可以使用属性 CurrentCell CurrentCellChanged 更新TextBox的事件 http://msdn.microsoft.com/en-us/libr...llchanged.aspx


有很多种可能性,你只需阅读通过它和选择你最喜欢的那个:)


DataGridView中还有一个属性CurrentRow。但是我担心你必须逐个获得其细胞的价值,例如假设您要在一个TextBox中显示5列,用空格分隔:

展开 | 选择 | Wrap | 行号


how to get the value from datagridview to textbox on c#?
im a beginner in c#.. and im having a hard time searching for the error free code for this.. need help!!!!

解决方案

To retrive text from one of DataGridView''s cells:

Expand|Select|Wrap|Line Numbers


...what if i want to select the whole row, not just the current cell??
will i put your code on the currentcellcontent of datagridview method..?


You can select current cell for example by clicking it - by subscribing to one of this 4 events (pick the one that suits you best):

- CellClicked http://msdn.microsoft.com/en-us/libr...cellclick.aspx
- CellContentClick http://msdn.microsoft.com/en-us/libr...tentclick.aspx
- CellContentDoubleClicked http://msdn.microsoft.com/en-us/libr...ubleclick.aspx
- CellDoubleClicked http://msdn.microsoft.com/en-us/libr...ubleclick.aspx

Or you can use the property CurrentCell and CurrentCellChanged event to update your TextBox http://msdn.microsoft.com/en-us/libr...llchanged.aspx

There are many possibilities, you just have to read through it and choose the one that you like best :)

There is also a property CurrentRow in DataGridView. But I''m afraid that you''ll have to get values of its cells one by one, e.g. lets assume you have 5 columns you want to display in one TextBox, separated by spaces:

Expand|Select|Wrap|Line Numbers


这篇关于如何在c#中从datagridview获取值到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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