Results 1 to 5 of 5

Thread: SelectedItem on ListView control

  1. #1

    Thread Starter
    Member
    Join Date
    May 2000
    Location
    NY
    Posts
    47

    Cool

    How can the value of the SelectedItem on a ListView control can be refreshed?

    Thank you,
    Rowena

  2. #2
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    LoCal
    Posts
    280
    Do you mean:

    Code:
    lvwList.SelectedItem.Text = "new text"
    Achichincle

    VB6 (VSEE SP5, W2KPro)
    ASP
    HTML

  3. #3

    Thread Starter
    Member
    Join Date
    May 2000
    Location
    NY
    Posts
    47
    Hi Achichincle,

    Thanks for replying. What I mean is I have a loop on how many records on a listview control. It checks if the listitem is selected or not. If it is selected, it gets the current value. However, when I am using this kind of code, it doesn't get the next value. It just gets the first value. Here's my sample program:

    With ListViewMetrics.ListItems
    For i = 1 To ListViewMetrics.ListItems.Count
    If ListViewMetrics.ListItems.Item(i).Selected = True Then
    'save the record in database
    'MsgBox ListViewMetrics.SelectedItem.Text
    sStratID = ListViewMetrics.SelectedItem.SubItems(2) 'Stratification Value
    sMetID = ListViewMetrics.SelectedItem.SubItems(3) 'Metric ID
    sDashID = ListViewMetrics.SelectedItem.SubItems(4) 'Dashboard ID

    End If
    Next i
    End With


    The value of sStratID, sMetID, sDashID is not refreshed with the new selected record in the listview control. What is wrong?

    Thank you very much!
    Rowena

  4. #4
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    LoCal
    Posts
    280
    I gotcha.

    Try:

    Code:
    sStratID = ListViewMetrics.ListItems(i).SubItems(2) 'Stratification Value 
    sMetID = ListViewMetrics.ListItems(i).SubItems(3) 'Metric ID 
    sDashID = ListViewMetrics.ListItems(i).SubItems(4) 'Dashboard ID
    The problem is that if you have more than one item selected in the listview it doesn't know which one you're referring to.

    I've also noticed that when you load items into a listview their .Selected property seems to be set to True eventhough they don't appear as selected on the listview display.

    What I've done is explicitly set the .Selected property to False when I'm loading the listview items in order to avoid this problem.

    Hope this helps...
    Achichincle

    VB6 (VSEE SP5, W2KPro)
    ASP
    HTML

  5. #5

    Thread Starter
    Member
    Join Date
    May 2000
    Location
    NY
    Posts
    47
    Hi Achichincle!

    Thank you so much because this works!!!

    Have a nice day,
    Rowena

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