加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

[VB.NET]DataGrid数据取到Textbox

发布时间:2020-12-16 23:37:06 所属栏目:大数据 来源:网络整理
导读:DataGrid数据取到Textbox 以前用VB,数据库操作不适应 以下代码从数据库取得数据显示到DataGrid Dim cString As String = server=192.168.1.13;database=test;user id=sa;password=123456 Dim cnNorthwind As SqlConnection = New SqlConnection(cString) Cr
DataGrid数据取到Textbox 以前用VB,数据库操作不适应 以下代码从数据库取得数据显示到DataGrid Dim cString As String = server=192.168.1.13;database=test;user id=sa;password=123456 Dim cnNorthwind As SqlConnection = New SqlConnection(cString) Create a SqlDataAdapter for the Suppliers table. Dim adpSuppliers As SqlDataAdapter = New SqlDataAdapter A table mapping tells the adapter what to call the table. adpSuppliers.TableMappings.Add( Table,Suppliers ) cnNorthwind.Open() Dim cmdSuppliers As SqlCommand = _ New SqlCommand( SELECT * FROM Suppliers,cnNorthwind) cmdSuppliers.CommandType = CommandType.Text adpSuppliers.SelectCommand = cmdSuppliers Console.WriteLine( The connection is open. ) ds = New DataSet( Suppliers ) adpSuppliers.Fill(ds) myGrid.DataSource = ds.Tables( Suppliers ) 现在想在MyGrid移动的时候把当前记录的SupplierID,CompanyName显示到Textbox1和Textbox1,有两个问题: 1、我会以下代码取得,但是我希望用字段名来取得,有没有办法 TextBox1.Text = myGrid.Item(myGrid.CurrentRowIndex,0) TextBox2.Text = myGrid.Item(myGrid.CurrentRowIndex,1) 2、DataGrid的什么事件可以检测到当前记录的移动,我用myGrid_CurCellChange事件没有反应。 谢谢。 __________________________________________________________________________ 顶下回家 __________________________________________________________________________ 可以用客户端Javascript实现 __________________________________________________________________________ 顶下 __________________________________________________________________________ 2.private void dataGrid1_MouseDown(object sender,System.Windows.Forms.MouseEventArgs e) { System.Drawing.Point pt= new Point(e.X,e.Y); DataGrid.HitTestInfo hti= this.dataGrid1.HitTest(pt); MessageBox.Show(hti.Row.ToString());//hti.Row就是你双击的行 } } __________________________________________________________________________ 谢谢楼上 用MouseDown、MouseUp不能检测到键盘操作的移动 第二个问题我基本上用CurCellChange解决了 __________________________________________________________________________ TextBox1.Text = myGrid.Item(myGrid.CurrentRowIndex,1) 我基本上使用datebinding __________________________________________________________________________ Me.UTE_GH.DataBindings.Add( Text,UltraGrid1.DataSource,工号 ) Me.UTE_XM.DataBindings.Add( Text,姓名 ) Me.UCE_XB.DataBindings.Add( Text,性别 ) __________________________________________________________________________ 谢谢 小黑MM __________________________________________________________________________

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读