Re: [2005] Why my listview's row not highlighted when I click on it?


I don't know what is the problem. I have already put fullrowselect as true and view as details at the properties of my listview. But I can't hightlight the row I click. Is it got to do with my codes What should I correct my code

VB Code: Public Class lost Private Sub lost_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not lvlost.SelectedItems.Count = 0 Then tbxtotal.Text = lvlost.SelectedItems(0).SubItems(5).Text lvlost.View = View.Details 'view stuff in listview lvlost.Columns.Add("Item's Id", 60, HorizontalAlignment.Left) lvlost.Columns.Add("Item's Title", 100, HorizontalAlignment.Left) lvlost.Columns.Add("Item's status", 80, HorizontalAlignment.Left) lvlost.Columns.Add("Loan date", 70, HorizontalAlignment.Left) lvlost.Columns.Add("Due date", 80, HorizontalAlignment.Left) lvlost.Columns.Add("Cost Price", 80, HorizontalAlignment.Left) Dim strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =C:\temp\db1.mdb" Dim con As OleDb.OleDbConnection Dim dr As OleDb.OleDbDataReader Dim cmd As New OleDb.OleDbCommand Dim strselect As String = "Select * from borrowrecord where BorrowerId = '" & Form1.tbxID.Text & "' And ItemStatus = True " con = New OleDb.OleDbConnection(strcon) 'create a new connection con = New OleDb.OleDbConnection(strcon) con.Open() cmd.Connection = con cmd.CommandText = strselect dr = cmd.ExecuteReader lvlost.Items.Clear() While dr.Read() Dim Item As New ListViewItem Item.Text = (dr("ItemId")) Item.SubItems.Add(dr("ItemTitle")) Item.SubItems.Add(dr("ItemStatus")) Item.SubItems.Add(dr("ItemLoanDate")) Item.SubItems.Add(dr("ItemDueDate")) Item.SubItems.Add(dr("costPrice")) lvlost.Items.Add(Item) End While dr.Close() ' If Not lvlost.SelectedItems.Count = 0 Then tbxtotal.Text = lvlost.SelectedItems(0).SubItems(5).Text End Sub Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click showlost.ShowDialog() End Sub Private Sub lvlost_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvlost.SelectedIndexChanged If Not lvlost.SelectedItems.Count = 0 Then tbxtotal.Text = lvlost.SelectedItems(0).SubItems(5).Text Dim strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =C:\temp\db1.mdb" Dim con As OleDb.OleDbConnection Dim dr As OleDb.OleDbDataReader Dim cmd As New OleDb.OleDbCommand Dim strselect As String = "Select * from borrowrecord where BorrowerId = '" & Form1.tbxID.Text & "' And ItemStatus = True " con = New OleDb.OleDbConnection(strcon) 'create a new connection con = New OleDb.OleDbConnection(strcon) con.Open() cmd.Connection = con cmd.CommandText = strselect dr = cmd.ExecuteReader lvlost.Items.Clear() While dr.Read() Dim Item As New ListViewItem Item.Text = (dr("ItemId")) Item.SubItems.Add(dr("ItemTitle")) Item.SubItems.Add(dr("ItemStatus")) Item.SubItems.Add(dr("ItemLoanDate")) Item.SubItems.Add(dr("ItemDueDate")) Item.SubItems.Add(dr("costPrice")) lvlost.Items.Add(Item) End While dr.Close() End SubEnd Class
Posted On: Saturday 3rd of November 2012 12:49:05 PM Total Views:  169
View Complete with Replies