[VB.NET]DataGrid数据取到Textbox

前端之家收集整理的这篇文章主要介绍了[VB.NET]DataGrid数据取到Textbox前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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 __________________________________________________________________________ 原文链接:https://www.f2er.com/vb/263400.html

猜你在找的VB相关文章