【问题标题】:Load Dev Express data grid row values into textboxes in VB.net将 Dev Express 数据网格行值加载到 VB.net 中的文本框中
【发布时间】:2015-03-16 21:26:37
【问题描述】:

当我单击相应的单元格时,我正在尝试将使用 Dev Express 设置的数据网格中的值加载到文本框中。

我可以使用 VS 2013 附带的普通 DataGrid 来做到这一点:

 Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    If e.RowIndex >= 0 Then
        Dim row As DataGridViewRow
        row = Me.DataGridView1.Rows(e.RowIndex)

        tbID.Text = row.Cells("id").Value.ToString
        tbFirstName.Text = row.Cells("firstname").Value.ToString
        tbLastName.Text = row.Cells("lastname").Value.ToString
        tbAddress.Text = row.Cells("address").Value.ToString

    End If
End Sub

但我似乎无法在 Dev Express 的 GridView 中找到一种方法来做同样的事情,我在 C# 但不是 VB.net 中找到了其他主题来解释如何做到这一点。

【问题讨论】:

    标签: vb.net visual-studio datagridview datagrid devexpress


    【解决方案1】:

    查看Obtaining and Setting Cell Values帮助文章-获取行单元格值可以使用ColumnView.GetRowCellValue方法如下:

    tbID.Text = GridView1.GetRowCellValue(2, "ID").ToString()
    

    【讨论】:

    • 您能否详细说明您的代码?我不是 VB.Net 的专业人士...请用 sub 显示一个示例。谢谢。
    【解决方案2】:

    您可以使用GridView.GetRowCellValue 方法从单元格中获取值。此外,您可以使用GridView.FocusedRowObjectChanged 事件来更新您的文本框:

    Private Sub gridView1_FocusedRowObjectChanged(sender As Object, e As FocusedRowObjectChangedEventArgs) Handles gridView1.FocusedRowObjectChanged
    
        Dim rowHandle = e.FocusedRowHandle
    
        tbID.Text = gridView1.GetRowCellValue(rowHandle, "id").ToString
        tbFirstName.Text = gridView1.GetRowCellValue(rowHandle, "firstname").ToString
        tbLastName.Text = gridView1.GetRowCellValue(rowHandle, "lastname").ToString
        tbAddress.Text = gridView1.GetRowCellValue(rowHandle, "address").ToString
    
    End Sub
    

    【讨论】:

    • 当我使用你发布的方法时,我得到Event FocusedRowObjectChanged cannot be found. 不要忘记我想使用 Dev Express Xtra Grid 而不是默认的数据网格。
    • @UriahsVictor 你的 DevExpress 版本是多少?你可以试试ColumnView.FocusedRowChanged 事件。
    • 我有 dev express 13.2 如果我需要在使用您最近评论的建议之前导入任何内容,请告诉我。我明天早上试试
    • @UriahsVictor ColumnView.FocusedRowObjectChanged 事件是在 13.2 版中引入的。在 Visual Studio 设计器中仔细查看 GridView 的可用事件。
    • 能否请您提供带有 sub 的代码的 sn-p 而不是仅仅粘贴那一行?正如我所说,我不是 VS 专业人士,所以我知道如何在 VS 附带的普通数据网格上做我想做的事,我只需要知道如何使用 Dev Express 来做。你真的尝试过你推荐的东西吗?请粘贴一个sn-p。
    【解决方案3】:

    这很容易实现...我所做的只是将 DataSource 附加到我的项目,然后从 DataSource 窗格中将 DEV Express XTraGridview 拖到表单中,然后我将窗格中的数据源类型更改为详细信息并将其拖到表单上,它们会自动同步。

    添加数据源:https://msdn.microsoft.com/en-us/library/w4dd7z6t.aspx?f=255&MSPPError=-2147217396

    【讨论】:

      猜你喜欢
      • 2017-09-04
      • 1970-01-01
      • 2021-04-22
      • 1970-01-01
      • 2019-05-02
      • 2013-04-25
      • 2017-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多