[VB.NET]listview问题

前端之家收集整理的这篇文章主要介绍了[VB.NET]listview问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
listview问题 1.选中listview一条记录,点删除按钮就把listview对应选择记录删除,但不删除对应选择数据库内容? 2.选中listview一条记录,点删除按钮就把listview对应选择的记录删除,同时删除对应选择数据库内容? 3.选中listview一条记录的一个单元格,如何使之变为编辑状态? __________________________________________________________________________ 1>綁定到數據集,刪除數據集中的一項,再綁定listview.数据库不會變化. 2>實現第一步的同時再加一個SQL刪除語句. 3>雙擊一項可以編輯吧,記得好像這樣. __________________________________________________________________________ For i As Integer = lvAddress.SelectedItems.Count - 1 To 0 Step -1 lvAddress.SelectedItems(i).Remove() Next 后边怎么加sql删除语句? Dim strsql As String strsql = String.Format( "delete from Address where mailid={1} ",row( "F "),row( "mailid ")) DB.ExecuteNonQuery(strsql) ?? __________________________________________________________________________ 上面就可以. 不過你的for 語句是刪所有項.不是選中的項. __________________________________________________________________________ 那怎么改呢?谢谢! __________________________________________________________________________ 选中listview一条记录,但不删除对应选择数据库内容? 代码例子看看? __________________________________________________________________________ 选中listview一条记录,同时删除对应选择数据库内容? 代码例子看看? __________________________________________________________________________ 先等一下,一会写给你看. __________________________________________________________________________ Public Class Form1 Private mIndex As Integer Private mTag As String Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged Try For Each Item As ListViewItem In Me.ListView1.SelectedItems If Item.Selected = True Then mIndex = Item.Index mTag = Item.Tag End If Next Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Form1_Load(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Load LoadData() End Sub Private Sub LoadData() Dim Item As ListViewItem With Me.ListView1 For i As Integer = 0 To 15 Item = New ListViewItem Item.Tag = i Item.Text = (i + 1).ToString & "abadec " Me.ListView1.Items.Add(Item) Next End With End Sub Private Sub btnDel_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnDel.Click Try Dim sql As String = " " Dim connstring As String = " " Dim cmd As New sqlClient.sqlCommand Dim conn As New sqlClient.sqlConnection(connstring) Me.ListView1.Items.RemoveAt(mIndex) sql = "delete datatable where id= " & mTag With cmd .CommandType = CommandType.Text .Connection = conn .CommandText = sql .ExecuteNonQuery() End With Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Class __________________________________________________________________________ 谢谢! 方便的话可以给我一个交流联系方式!谢谢 __________________________________________________________________________ MSN fht123321@hotmail.com __________________________________________________________________________ 你看这样删除?还要什么条件? Dim row As DataRow Dim li As ListViewItem lvAddress.SelectedItems(0).Tag = li.Text Dim j As Integer row = li.Tag Dim strsql As String strsql = String.Format( "delete from Address where SYSID={0} ",row( "SYSID ")) DB.ExecuteNonQuery(strsql) __________________________________________________________________________ 或者什么改就能删除,我现在删除不了数据库的数据.谢谢! __________________________________________________________________________ 表Address中关键字是SYSID __________________________________________________________________________ 把下面代码拷过去: Public Class Form1 Private mIndex As Integer Private mTag As String Private Sub Form1_Load(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Load LoadData() End Sub Private Sub LoadData() Dim Item As ListViewItem Dim connstring As String = " " Dim conn As New sqlClient.sqlConnection(connstring) Dim sql As String = " " Dim m_ds As New DataTable sql = "select * from Address " Dim sqlAdpt As New sqlClient.sqlDataAdapter(sql,conn) sqlAdpt.Fill(m_ds) If m_ds.Rows.Count > 0 Then With Me.ListView1 For Each mRow As DataRow In m_ds.Rows Item = New ListViewItem Item.Tag = mRow( "SYSID ") Item.Text = mRow( "SYSID ") Me.ListView1.Items.Add(Item) Next End With End If End Sub Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged Try For Each Item As ListViewItem In Me.ListView1.SelectedItems If Item.Selected = True Then mIndex = Item.Index mTag = Item.Tag End If Next Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub btnDel_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnDel.Click Try Dim sql As String = " " Dim connstring As String = " " Dim cmd As New sqlClient.sqlCommand Dim conn As New sqlClient.sqlConnection(connstring) Me.ListView1.Items.RemoveAt(mIndex) sql = "delete datatable where SYSID= " & mTag With cmd .CommandType = CommandType.Text .Connection = conn .CommandText = sql .ExecuteNonQuery() End With Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Class __________________________________________________________________________ 原文链接:https://www.f2er.com/vb/263991.html

猜你在找的VB相关文章