【问题标题】:Passing DataGridView selected value to a text box将 DataGridView 选定值传递给文本框
【发布时间】:2016-02-07 11:34:27
【问题描述】:
Private Sub DataGridViewMachine_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridViewMachine.CellContentClick
    frmAddNewWrkReq.txtbxAssetName.Text = DataGridViewMachine.SelectedRows(DataGridViewMachine.CurrentRow.Index).Cells(1).Value.ToString
    Me.Hide()
End Sub

如何从 datagridview 中获取选定的值到文本框中?

【问题讨论】:

    标签: vb.net datagridview


    【解决方案1】:

    试试这个代码:

    frmAddNewWrkReq.txtbxAssetName.Text = DataGridViewMachine.CurrentRow.Cells("name_of_the_cell").Value.ToString
    

    可能需要在 DataGridViewMachine 上设置 SelectMode=FullRowSelect

    【讨论】:

    • 我试过上面的代码。工作,没有错误。确保您拥有正确的控件名称。您收到任何错误消息?
    • 谢谢。我试试看
    【解决方案2】:

    你可以试试这个代码

    frmAddNewWrkReq.txtbxAssetName.Text = DataGridViewMachine.Rows(DataGridViewMachine.CurrentRow.Index).Cells(1).Value.ToString
    

    【讨论】:

      猜你喜欢
      • 2015-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-14
      • 1970-01-01
      • 2016-04-20
      • 1970-01-01
      • 2017-08-31
      相关资源
      最近更新 更多