2 questions about ComboBox

Posted on 2004-10-31
Last Modified: 2010-04-23
Let's say that I have two comboboxes named cboDay and cboMonth.

1) Let's say i want to type something into my combobox and when i click enter, i want that text that i typed to be automatically added to the list. So the next time i drop down my combobox, i want that text to be in the list.
I already set dropDownStyle to DropDown. If i have to type a code for that, could you please tell me in what procedure to write it?
cboDay_KeyPress? cboDay_Enter?

2)cboMonth has months of the year from 1 to 12. CboDays initially has numbers from 1 to 31. But not all the months has same number of days.
How will i make it so that if user clicks 2 from cboMonth, days in cboDay will remove 30 and 31 from the list? (February may have 29 days but not 30 and 31.) And when user clicks 3 from cboMonth , 30 and 31 will be added to cboDays list.
Is it gonna be something like,
 if cboMonth.selectedIndex = 1 then

Question by:aeusta
    LVL 2

    Expert Comment


    At KeyPress Check for

    e.KeyChar.GetHashCode  it is 851981 for Enter.


    You Add the days at run time only first check the month and then add item in the combo through a loop.

    create three conditions for 28 , 30, 31  Also 29 if consider leep year .


    Author Comment

    Part A works, but can you be more spesific on part b?
    What is the procedure to create those conditions? It would be nice if you could write the exact code.
    LVL 2

    Accepted Solution

    try like this way

    Dim i As Integer
            Select Case (cboMonth.Text)
                Case 1, 3, 5, 7, 8, 10, 12
                    For i = 1 To 31
                Case 2
                    For i = 1 To 28
                Case 4, 6, 9, 11
                    For i = 1 To 30
                Case Else

            End Select

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now