Results 1 to 4 of 4

Thread: ListView Problem !!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108

    ListView Problem !!

    i have a problem with the listview

    i have 2 combobox and 2 textbox and one listview call listview3

    after i add in the data to the listview how can i hightlight the item that i add in to the listview ????

    thanx for the help


  2. #2
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.       ListView1.Items.Add(TextBox1.Text).BackColor = Color.Brown 'monkey
    3.       If ListView1.Items.Count > 1 Then
    4.          ListView1.Items(ListView1.Items.Count - 2).BackColor = Nothing
    5.       End If
    6.    End Sub
    hope i don't bark the wrong tree. though monkeys don't bark...

  3. #3
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Well Brown since you seem to know your ListView pretty well, can you tell me why my SubItems won't Add??

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim LvItem As New ListViewItem
    3.         Dim int1, int2, ans As Integer
    4.  
    5.         For int1 = 1 To 12
    6.             For int2 = 1 To 12
    7. ' Works fine!
    8.                 LvItem = lstTable.Items.Add(int1.ToString)
    9. ' Doesn't Work
    10.                 LvItem.SubItems.Add = ("X")
    11. ' Doesn't Work
    12.                 LvItem.SubItems.Add = (int2.ToString)
    13. ' Doesn't Work
    14.                 LvItem.SubItems.Add = ("=")
    15. ' Works fine!
    16.                 ans = int1 * int2
    17. ' Doesn't Work
    18.                 LvItem.SubItems.Add = (ans.ToString)
    19.             Next
    20.         Next
    21.  
    22.     End Sub
    Twisted

  4. #4
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    There are a couple of problems with your code.
    First you are trying to add subitems to an item that was creaetd from a listview with predefined column headers so your subitems already exist.
    Second you are trying to assign a string to an object reference that expects a subitem object.

    try this:
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim LvItem As New ListViewItem
    3.         Dim int1, int2, ans As Integer
    4.  
    5.         For int1 = 1 To 12
    6.             LvItem = lstTable.Items.Add(int1.ToString)
    7.             For int2 = 1 To 12
    8.                 LvItem.SubItems(1).Text = ("X")
    9.                 LvItem.SubItems(2).Text = (int2.ToString)
    10.                 LvItem.SubItems(3).Text = ("=")
    11.                 ans = int1 * int2
    12.                 LvItem.SubItems(4).Text = (ans.ToString)
    13.             Next
    14.         Next
    15.     End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width