【问题标题】:Retrieving data from ListView control in VB.NET从 VB.NET 中的 ListView 控件中检索数据
【发布时间】:2011-02-07 04:59:44
【问题描述】:

我有一个详细模式下的 ListView 设置,如下所示:

当用户按下删除按钮时,我需要继续从数据库中删除他们的记录。这我可以做得很好,但我坚持如何检索 ListView 控件中突出显示的数据。我尝试过使用 Google,但我发现的所有示例均无效。

有人可以帮我吗?

【问题讨论】:

  • 如何在ListView中绑定(放信息)?手动,使用数据源创建的数据集,...?
  • 我在一个单独的子例程中从 MS Access 数据库中获取结果,并将结果直接广告到 ListView 控件。

标签: database vb.net listview highlight


【解决方案1】:

您应该能够通过以下方式获取底层对象:

ListView1.SelectedItems(0)

一旦你从数据库中删除它,你应该重新绑定数据。

【讨论】:

    【解决方案2】:
    Dim name, room, subject, date, period As String
    
    If listviewName.SelectedItems.Count > 0 then
    
            '*********** transfer selected data on declare String variable ************'
            name= listviewName.SelectedItems(0).SubItems(0).Text
            room = listviewName.SelectedItems(0).SubItems(1).Text
            subject = listviewName.SelectedItems(0).SubItems(2).Text
            date= listviewName.SelectedItems(0).SubItems(3).Text
            period= listviewName.SelectedItems(0).SubItems(4).Text
    
            '*********** delete **************'
            cmd1.Connection = MYSQLCON
            MYSQLCON.Open()
            cmd1.CommandText = "DELETE FROM tablename WHERE columnname = '" & name & "'"
            reader = cmd1.ExecuteReader
            MYSQLCON.Close()
    
    End If
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 2023-04-04
      • 1970-01-01
      • 2015-06-12
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多