Results 1 to 8 of 8

Thread: Why my coding wont work ?????

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108

    Unhappy Why my coding wont work ?????

    For TempLooping = 0 To TempStoreListview3 - 1

    If ListView3.Items(TempLooping).SubItems(1).Text.Equals(Year_ComboBox.Text) Then

    ListView3.Items(TempLooping).SubItems(PositionOfTempClient).BackColor = Color.Cyan

    End If

    Next


    Why my coding wont work ?????

  2. #2
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Well, I was going to try to fix this but there are too many unknowns...
    What is the datatype for TimeLooping
    What is the datatype for TempStoreListView3 and what is it's value
    What is the datatype for PositionOfTempClient and what is it's value

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    And more importantly, what do you mean by "not working"? Error message or unexpected behavior?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    i cannot help me to highlight the row of the item that i add in

    i use the for loop to help me to search which row and column that i need to add in the data in the listview

    and after i add in the data, the list view will highlight the row and column that i have addin the data

  5. #5
    New Member
    Join Date
    Mar 2004
    Posts
    3
    For TempLooping = 0 To TempStoreListview3 - 1

    If ListView3.Items(TempLooping).SubItems(1).Text.Equals(Year_ComboBox.Text) Then

    ListView3.Items(TempLooping).SubItems(PositionOfTempClient).BackColor = Color.Cyan

    End If

    Next
    I dont know but it looks like you're only testing one subitem. Take a look at your If statement, shouldn't it be:

    If ListView3.Items(TempLooping).SubItems(PositionOfTempClient).Text.Equals(Year_ComboBox.Text) Then

    instead of SubItems(1) ?

  6. #6
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    i think this is what you are looking for.
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.       Dim cn As New SqlConnection()
    3.       cn.ConnectionString = "integrated security=true;initial catalog=northwind"
    4.       cn.Open()
    5.  
    6.       Dim cmdtext As String = "select * from categories"
    7.       Dim cm As New SqlCommand(cmdtext, cn)
    8.       Dim dr As SqlDataReader = cm.ExecuteReader
    9.       Dim i As Integer = 0
    10.       While dr.Read
    11.          ListView1.Items.Add(dr.GetValue(0))
    12.          ListView1.Items(i).SubItems.Add(dr.GetValue(1))
    13.          ListView1.Items(i).SubItems.Add(dr.GetValue(2))
    14.          i += 1
    15.       End While
    16.  
    17.       brown_monkey_look("Cheeses")
    18.    End Sub
    19.  
    20.    Sub brown_monkey_look(ByVal s As String)
    21.       Dim i As Integer
    22.       For i = 0 To ListView1.Items.Count - 1
    23.          Dim li As ListViewItem = ListView1.Items(i)
    24.          li.UseItemStyleForSubItems = False
    25.          Dim si As ListViewItem.ListViewSubItem
    26.          For Each si In li.SubItems
    27.             If si.Text.Equals(s) Then
    28.                si.BackColor = Color.Brown ' monkey
    29.             End If
    30.          Next
    31.       Next
    32.    End Sub
    hope i don't bark the wrong tree. though monkeys don't bark...

  7. #7
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    That's some pretty creative coding, how did you gleen all that from the information provided in these posts??

  8. #8
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    he said highlighting subitem???

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