Results 1 to 8 of 8

Thread: [RESOLVED] Setting Focus on the last item in the listview

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    24

    Resolved [RESOLVED] Setting Focus on the last item in the listview

    Hi

    How can I set the focus on the last item in the listview control?

    item.selected=true doesnt set it focused.

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Setting Focus on the last item in the listview

    listview1.listitems(listview1.listitems.count).selected = true

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    24

    Re: Setting Focus on the last item in the listview

    Quote Originally Posted by leinad31
    listview1.listitems(listview1.listitems.count).selected = true
    not working... while the listview is being populated.

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Setting Focus on the last item in the listview

    does the listview have the focus? If you want the selected item to be highlighted even when listview loses focus.

    ListView1.HideSelection = False

    If your listview is set to muliselection then you'll have to use EnsureVisible

    And if its while being populated, then set the listitem's Selected property and call ensurevisible just after being added.

    Use this syntax so you have a reference, in this case lstNew holds the reference to the just added listitem

    VB Code:
    1. Dim lstNew As ListItem
    2.  
    3.    Set lstNew = ListView1.ListItems.Add
    4.    lstNew.Text = "Test"
    5.    lstNew.Selected = True
    6.    lstNew.EnsureVisible
    Last edited by leinad31; Oct 22nd, 2006 at 12:12 PM.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    24

    Re: Setting Focus on the last item in the listview

    Quote Originally Posted by leinad31
    does the listview have the focus? If you want the selected item to be highlighted even when listview loses focus.

    ListView1.HideSelection = False

    If your listview is set to muliselection then you'll have to use EnsureVisible

    And if its while being populated, then set the listitem's Selected property and call ensurevisible just after being added.

    Use this syntax so you have a reference, in this case lstNew holds the reference to the just added listitem

    VB Code:
    1. Dim lstNew As ListItem
    2.  
    3.    Set lstNew = ListView1.ListItems.Add
    4.    lstNew.Text = "Test"
    5.    lstNew.Selected = True
    6.    lstNew.EnsureVisible
    WORKING................... PROBLEM SOLVED!
    Last edited by sufyaaan; Oct 22nd, 2006 at 12:18 PM.

  6. #6
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Setting Focus on the last item in the listview

    eh? check everything... are you sure the listview is enabled? are you sure it can receive focus (on the active form), or you can select items with clicks? are you sure you don't have code elsewhere that's setting selected = false and setting listview1.selecteditem = nothing?

    and post the code for populating it.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    24

    Re: Setting Focus on the last item in the listview

    Quote Originally Posted by leinad31
    eh? check everything... are you sure the listview is enabled? are you sure it can receive focus (on the active form), or you can select items with clicks? are you sure you don't have code elsewhere that's setting selected = false and setting listview1.selecteditem = nothing?

    and post the code for populating it.
    ITS WORKING! THANKS! YOU ROCK! (y)

  8. #8
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Setting Focus on the last item in the listview

    Ok. Pls take the time to mark the thread as resolved

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