CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [RESOLVED] Selectively prevent a combobox from scrolling past a certain point Visual Studio 2012

  1. #1
    Join Date
    May 2019
    Location
    Michigan
    Posts
    35

    [RESOLVED] Selectively prevent a combobox from scrolling past a certain point Visual Studio 2012

    I have two combo boxes on a form.

    Name:  Form3 example.jpg
Views: 29
Size:  22.3 KB


    Both of them contain the letters A - Z. One is loaded foreword (A-Z), the other backward (Z-A).

    They also hold the asterisk (*) symbol. They each have 26 indexes (not counting -1).

    Currently when a checkbox is checked, the asterisk symbol is selected for both combo boxes and they are disabled - works great.

    If the checkbox is NOT checked, I would like to prevent the user from scrolling to that "*" symbol using the UP/DOWN arrows
    of the combo box control.

    In summary: I only want the checkbox to select that indexed item.

    I tried to manually add and remove the "*" but the value where the asterisk is added is changed - I don't want that.

    Here is the checkbox code:

    Code:
    Private Sub Rnd_Letters_CheckedChanged(sender As Object, e As EventArgs) Handles Rnd_Letters.CheckedChanged
            Rnd_Letters.Font = IIf(Rnd_Letters.Checked = True, New Font(Rnd_Letters.Font, FontStyle.Bold), New Font(Rnd_Letters.Font, FontStyle.Regular))
            ConfigSet = True
    
            If Rnd_Letters.Checked = False Then
                Rnd_Letters.Refresh()
                ComboBox1.Enabled = True
                ComboBox2.Enabled = True
                ComboBox1.SelectedIndex = 0         ' Shows the first letter in the combobox
                ComboBox1.Refresh()
                ComboBox2.SelectedIndex = 0         ' Shows the first letter in the combobox
                ComboBox2.Refresh()
                No_Repeats.Checked = False
                No_Repeats.Enabled = False
                RndSet = False
            ElseIf Rnd_Letters.Checked = True Then
                No_Repeats.Enabled = True
                RndSet = True
                ComboBox1.SelectedIndex = 26        ' Selects the * symbol
                ComboBox1.Enabled = False
                ComboBox2.SelectedIndex = 26        ' Selects the * symbol
                ComboBox2.Enabled = False
                TextBox1.Text = "0"
            End If
    
            ConfigSet = False
            Check_Defaults()
            OKToolStripMenuItem.Enabled = True
            SAVEToolStripMenuItem.Enabled = True
        End Sub

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,461

    Re: Selectively prevent a combobox from scrolling past a certain point Visual Studio

    Either disable the comboboxes, or remove items that shouldn't be selected.

  3. #3
    Join Date
    May 2019
    Location
    Michigan
    Posts
    35

    Re: Selectively prevent a combobox from scrolling past a certain point Visual Studio

    Removing the "*" works great. It's when I try to put it back. Doing so replaces one of the letters stored. Not good.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,461

    Re: Selectively prevent a combobox from scrolling past a certain point Visual Studio

    Quote Originally Posted by oldGMtireman View Post
    Removing the "*" works great. It's when I try to put it back. Doing so replaces one of the letters stored. Not good.
    You have control over the list, if you can't figure out how to insert an item at a specific position, then delete the items and reinsert them.

  5. #5
    Join Date
    May 2019
    Location
    Michigan
    Posts
    35

    Re: Selectively prevent a combobox from scrolling past a certain point Visual Studio

    You were correct. I was populating the list dynamically when the form loaded and added the "*" at that time. I removed that.
    Then I had the checkbox add the "*" when checked and replaced the list with a call to the code that loaded it to begin with.
    DONE!
    Thank You!!!!!!!!!!!!!!!!!!

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,461

    Re: [RESOLVED] Selectively prevent a combobox from scrolling past a certain point Vis

    Great news

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)