将文本框链接到datagridview单元格中的单元格 [英] linking textbox to cell in a datagridview cell

查看:103
本文介绍了将文本框链接到datagridview单元格中的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在datagridview中查看数据表时,其中一列是

" note"这个领域可能很长。我想在datgridview下面的文本框中显示数据网格显示的当前所选行的

字段

。我目前已将其修复,因此如果您点击

行,该行的备注字段将放入文本框中。我希望这个

在行中移动时是自动的。


此外,注释字段是允许它们被允许的两个字段之一

在查看datagridview时进行编辑。他们当然想要在文本框中编辑它。
。如何将这些编辑自动放回到
datagridview / datatable中。我在想应该有一些方法将
文本框的数据源设置为一个单元格或者什么东西所以在其中编辑的是什么是
在datagridview /中编辑数据表。

When viewing a datatable in a datagridview one of the columns in it is a
"note" field which can be quite long. I would like to have the note
field of the currently selected row of the datagrid display in a textbox
below the datgridview. I currently have it fixed so if you click on a
row the note field from that row is put in the textbox. I''d like this
to be automatic as they move through rows.

Also the note field is one of two fields that they will be allowed to
edit while viewing the datagridview. They''d of course want to edit it
in textbox. How do I get these edits to automatically be put back in
the datagridview/datatable. I''m thinking there should be some way to
set the datasource of the textbox to a cell or something so what is
edited in it is edited in the datagridview/datatable.

推荐答案

一直在看第一部分。我尝试了DataGridView1.RowEnter和

RowLeave事件,两者似乎都显示了行中的单元格我只剩下
了!我不明白。他们都?!我可以看到rowleave,因为它可能会在单元格离开时从单元格中获取数据,但是rowenter应该从它正在进入的行中获取

单元格。 />

RowStateChanged显然不会在从一行到另一行移动时发射。


最后这似乎有效:

Private Sub DataGridView1_RowPostPaint(ByVal sender As Object,ByVal e

As System.Windows.Forms.DataGridViewRowPostPaintEvent Args)句柄

DataGridView1.RowPostPaint

如果不是IsDBNull(DataGridView1.CurrentRow.Cells(17).Value)那么

TextBox1.Text = DataGridView1.CurrentRow.Cells(17).Value

结束如果

结束子


评论?


转到AM的第2部分问题。希望有人会在一夜之间有一些想法,我可以尝试。


cj写道:
been looking at the first part. I tried DataGridView1.RowEnter and
RowLeave events and both seemed to show the cell from the row I just
left! I don''t get that. Both of them?! I can see rowleave as it might
grab the data from the cell as it leaves but rowenter should get the
cell from the row that it''s entering.

RowStateChanged sadly apparently doesn''t fire when moving from row to row.

Finally this seems to work:

Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e
As System.Windows.Forms.DataGridViewRowPostPaintEvent Args) Handles
DataGridView1.RowPostPaint
If Not IsDBNull(DataGridView1.CurrentRow.Cells(17).Value) Then
TextBox1.Text = DataGridView1.CurrentRow.Cells(17).Value
End If
End Sub

Comments?

Moving on to part 2 of my question in the AM. Hopefully someone will
have some ideas on that overnight that I can try.

cj wrote:

在datagridview中查看数据表时,其中一列是

" note"这个领域可能很长。我想在datgridview下面的文本框中显示数据网格显示的当前所选行的

字段

。我目前已将其修复,因此如果您点击

行,该行的备注字段将放入文本框中。我希望这个

在行中移动时是自动的。


此外,注释字段是允许它们被允许的两个字段之一

在查看datagridview时进行编辑。他们当然想要在文本框中编辑它。
。如何将这些编辑自动放回到
datagridview / datatable中。我在想应该有一些方法将
文本框的数据源设置为一个单元格或者什么东西所以在其中编辑的是什么是
在datagridview /中编辑数据表。
When viewing a datatable in a datagridview one of the columns in it is a
"note" field which can be quite long. I would like to have the note
field of the currently selected row of the datagrid display in a textbox
below the datgridview. I currently have it fixed so if you click on a
row the note field from that row is put in the textbox. I''d like this
to be automatic as they move through rows.

Also the note field is one of two fields that they will be allowed to
edit while viewing the datagridview. They''d of course want to edit it
in textbox. How do I get these edits to automatically be put back in
the datagridview/datatable. I''m thinking there should be some way to
set the datasource of the textbox to a cell or something so what is
edited in it is edited in the datagridview/datatable.


2007年12月4日星期二15:51:31 -0500,cj< cj@nospam.nospamwrote:
On Tue, 04 Dec 2007 15:51:31 -0500, cj <cj@nospam.nospamwrote:

>在datagridview中查看数据表时,其中一列是
note。这个领域可能很长。我想在datgridview下面的文本框中显示当前所选数据网格行的注释
字段。我目前已将其修复,因此如果您单击
行,该行中的备注字段将放入文本框中。我希望这个
在行中移动时是自动的。

注意字段也是允许在查看时编辑的两个字段之一。 datagridview的。他们当然想在文本框中编辑它。如何将这些编辑自动放回到datagridview / datatable中。我在想应该有一些方法来将文本框的数据源设置为单元格或其他东西,以便在datagridview / datatable中编辑在其中编辑的内容。
>When viewing a datatable in a datagridview one of the columns in it is a
"note" field which can be quite long. I would like to have the note
field of the currently selected row of the datagrid display in a textbox
below the datgridview. I currently have it fixed so if you click on a
row the note field from that row is put in the textbox. I''d like this
to be automatic as they move through rows.

Also the note field is one of two fields that they will be allowed to
edit while viewing the datagridview. They''d of course want to edit it
in textbox. How do I get these edits to automatically be put back in
the datagridview/datatable. I''m thinking there should be some way to
set the datasource of the textbox to a cell or something so what is
edited in it is edited in the datagridview/datatable.



你不能只将文本框绑定到网格的

数据源中的相应属性吗?

Can''t you just bind the textbox to the appropriate property in the
data source of the grid?


你好Cj,


#1,我认为DataGridView.RowEnter更适合你的要求;在

这个事件中,DataGridViewCellEventArgs.RowIndex应该报告当前的

输入行索引。如果没有,你能提供一个简单的样本来证明你的问题吗?


#2,就像杰克建议的那样,你也可以将TextBox绑定到相同的

数据源作为DataGridView。 Winform数据绑定机制将有助于确保这两个控件之间的数据同步。


谢谢。


Best问候,

Jeffrey Tan

微软在线社区支持

================== ================================

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ==========

此帖子按原样提供。没有保证,也没有授予任何权利。

Hi Cj,

#1, I think DataGridView.RowEnter is more suitable for your requirement; in
this event, DataGridViewCellEventArgs.RowIndex should report the current
enterring row index. If not, can you provide a simple sample to demonstrate
your problem?

#2, Just as Jack suggested, you may also bind the TextBox to the same
datasource as the DataGridView. Winform databinding mechanisum will help to
ensure the data synchronization between these two controls.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


这篇关于将文本框链接到datagridview单元格中的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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