How can I auto scroll to SelectedIndex?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How can I auto scroll to SelectedIndex?

  1. #1
    Join Date
    Apr 2004
    Posts
    158

    How can I auto scroll to SelectedIndex?

    After I have selected a entry from my combo box and recorded it's selected index, and then clear and re-list the combo box, how can i then have the combo box scroll to the selected index that I have recorded?

    Sorry if I am hard to understand, but I don't know all the techie talk.

    Thank you.
    I use VB.Net 2008 in all my wash, for those whiter whites.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,074

    Re: How can I auto scroll to SelectedIndex?

    This *almost* works, but you'll get the idea with which events to use and which properties of the CB to manipulate :

    Code:
    Public Class Form1
        Private blnRecorded As Boolean
        Private intNewIndex As Integer
        Private arrComboItems() As String = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"}
    
        Private Sub ComboBox1_DropDown(sender As Object, e As System.EventArgs) Handles ComboBox1.DropDown
            ComboBox1.Items.AddRange(arrComboItems)
    
            If blnRecorded Then
                ComboBox1.SelectedIndex = intNewIndex
                blnRecorded = False
    
            End If
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    
            intNewIndex = ComboBox1.SelectedIndex
            ComboBox1.Items.Clear()
            blnRecorded = True
    
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            MessageBox.Show(intNewIndex.ToString)
        End Sub
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            ComboBox1.Items.AddRange(arrComboItems)
        End Sub
    End Class

  3. #3
    Join Date
    Apr 2004
    Posts
    158

    Re: How can I auto scroll to SelectedIndex?

    Thanks, but with with this the item is selected, what I need is for the combo box to scroll to the area where the last selected index was without selecting it. If you get my drift?

    I think in the old VB you had something like combobox1.listindex()
    Last edited by dajunka; September 24th, 2013 at 03:42 AM.
    I use VB.Net 2008 in all my wash, for those whiter whites.

  4. #4
    Join Date
    Apr 2004
    Posts
    158

    Re:(SOLVED) How can I auto scroll to SelectedIndex?

    For instance, let say I have 2 combobox and I want to take the selectedindex from the first one, then have the second combobox scroll to the same index but without the index being highlighted or selected.

    Update: Okay I found a way.

    Thank you.
    Last edited by dajunka; September 25th, 2013 at 02:31 PM.
    I use VB.Net 2008 in all my wash, for those whiter whites.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center