如何双击数据网格控件并将文本释放到文本框。 [英] How to double click a datagrid control and release the text to a textbox.

查看:80
本文介绍了如何双击数据网格控件并将文本释放到文本框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,我想从数据网格中选择一个文本,即在双击特定行但未获得结果之后。这是我的示例代码。





Hi friends, please i want to pick a text from a datagrid,that is after double clicking a particular row but am not getting the result. This is my sample code.


Private Sub GridName_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GridName.DoubleClick


txtName.Text = GridName.SelectedRows(0).Cells("colUserName").Value.ToString()
txtAddress.Text = GridName.SelectedRows(1).Cells("colAddress").Value.ToString()
txtCity.Text = GridName.SelectedRows(2).Cells("colCity").Value.ToString()


    End Sub





期待您的帮助。



谢谢。



Looking forward for your help.

Thanks.

推荐答案

尝试这个(我认为你不能通过列名访问单元格)。替换为实数,单元格的真实索引而不是我在代码中放入的名称:

Try this (I think you cannot access cells through column names). Replace with real numbers, real indexes of the cells instead of names I put in the code:
txtName.Text = GridName.CurrentRow.Cells(colUserNameIndex).Value
txtAddress.Text = GridName.CurrentRow.Cells(colAddressIndex).Value
txtCity.Text = GridName.CurrentRow.Cells(colCityIndex).Value





如果你想使用字段名,请使用



If you want to use field names, use

Dim drv as DataRowView = DirectCast(GridName.CurrentRow.DataBoundItem, DataRowView)
txtName.Text = drv("UserName")
txtAddress.Text = drv("Address")
txtCity.Text = drv("City")


这篇关于如何双击数据网格控件并将文本释放到文本框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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