Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Listbox maximum?

Listbox maximum?

Scheduled Pinned Locked Moved Visual Basic
question
12 Posts 4 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M MallardsReach

    How do I restrict a Listbox to 4 entries? Thanks for looking. Solved, found this Listbox1.Items.Count

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #3

    Simple; add a post-it to the monitor that says "don't add more than four in THE listbox". Download the UX-guide from MS (its free) and read why you are using the wrong control, and which one you should be using instead. I'll bet it will point out checkboxes.

    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

    M 1 Reply Last reply
    0
    • D Dave Kreskowiak

      The ListBox doesn't support such limitations. You'd have to create your own ListBox and add that functionality.

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      M Offline
      M Offline
      MallardsReach
      wrote on last edited by
      #4

      It may not be supported but using this

      If LstMat1.Items.Count = 4 Then

      it did what I required.

      D 1 Reply Last reply
      0
      • L Lost User

        Simple; add a post-it to the monitor that says "don't add more than four in THE listbox". Download the UX-guide from MS (its free) and read why you are using the wrong control, and which one you should be using instead. I'll bet it will point out checkboxes.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        M Offline
        M Offline
        MallardsReach
        wrote on last edited by
        #5

        Tried adding post-it note to monitor but it still didn't work? Just to recap:-- I need 5 Listboxes one Main Listbox (MLB) and four others LB1, LB2, LB3 and LB4. After entering names in a Textbox and pressing enter the first name goes in to LB1 so does the 2 name, the 3rd and the 4th. The 5th name goes in to LB2 so does name 6, 7 and 8. LB3 gets the next 4 and LB4 gets the next four. Any other names that get entered go in to MLB. Under each LB is a button and when pressed the four names in that LB get added to the bottom of the MLB and the top 4 names in the MLB go in to LB1, 2, 3 or 4 depending on which button under which LB was pressed. Despite all the help and advice offered I have this working exactly as I want with no errors. So it shows, that sometimes, the best help is when your help yourself. And if it still proves difficult then visit a site that offers constructive help and advice.

        L 1 Reply Last reply
        0
        • M MallardsReach

          It may not be supported but using this

          If LstMat1.Items.Count = 4 Then

          it did what I required.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #6

          Seriously, I thought you were writing this for other developers to use. Of course, it's that easy if you're the only one doing this for a single ListBox. If you're looking to reuse this in multiple places, you'd have to make your own version of the ListBox.

          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
          Dave Kreskowiak

          M 1 Reply Last reply
          0
          • M MallardsReach

            Tried adding post-it note to monitor but it still didn't work? Just to recap:-- I need 5 Listboxes one Main Listbox (MLB) and four others LB1, LB2, LB3 and LB4. After entering names in a Textbox and pressing enter the first name goes in to LB1 so does the 2 name, the 3rd and the 4th. The 5th name goes in to LB2 so does name 6, 7 and 8. LB3 gets the next 4 and LB4 gets the next four. Any other names that get entered go in to MLB. Under each LB is a button and when pressed the four names in that LB get added to the bottom of the MLB and the top 4 names in the MLB go in to LB1, 2, 3 or 4 depending on which button under which LB was pressed. Despite all the help and advice offered I have this working exactly as I want with no errors. So it shows, that sometimes, the best help is when your help yourself. And if it still proves difficult then visit a site that offers constructive help and advice.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #7

            MallardsReach wrote:

            So it shows, that sometimes, the best help is when your help yourself. And if it still proves difficult then visit a site that offers constructive help and advice.

            My advice remains unchanged, as well as the verdict, as non-typical use of common controls is confusing to typical end-users.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            M 1 Reply Last reply
            0
            • D Dave Kreskowiak

              Seriously, I thought you were writing this for other developers to use. Of course, it's that easy if you're the only one doing this for a single ListBox. If you're looking to reuse this in multiple places, you'd have to make your own version of the ListBox.

              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
              Dave Kreskowiak

              M Offline
              M Offline
              MallardsReach
              wrote on last edited by
              #8

              Hi Dave, I only ever code for myself, it's a hobby nothing more, this program is for the bowling club that I attend on Wednesday nights, we have 4 mats and when your game is finished the names of the 4 players go back in to the pool and the next 4 players use the mat you've just left. Below is the complete code, not that you need it but you can see what I did, no comments as it's only for me to play with.

              Public Class Form1

              Private Sub TextBox1\_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
                  If e.KeyCode = Keys.Enter Then
                      Static Fillup = 1
                      Select Case Fillup
                          Case 1
                              LstMat1.Items.Add(TextBox1.Text)
                              TextBox1.Text = String.Empty
                              If LstMat1.Items.Count = 4 Then
                                  Fillup = 2
                              End If
                          Case 2
                              LstMat2.Items.Add(TextBox1.Text)
                              TextBox1.Text = String.Empty
                              If LstMat2.Items.Count = 4 Then
                                  Fillup = 3
                              End If
                          Case 3
                              LstMat3.Items.Add(TextBox1.Text)
                              TextBox1.Text = String.Empty
                              If LstMat3.Items.Count = 4 Then
                                  Fillup = 4
                              End If
                          Case 4
                              LstMat4.Items.Add(TextBox1.Text)
                              TextBox1.Text = String.Empty
                              If LstMat4.Items.Count = 4 Then
                                  Fillup = 5
                              End If
                          Case 5
                              LstNames.Items.Add(TextBox1.Text)
                              TextBox1.Text = String.Empty
                      End Select
                  End If
              End Sub
              
              Private Sub BtnMat1\_Click(sender As Object, e As EventArgs) Handles BtnMat1.Click
                  Static num = 3
                  For clearLb = 0 To 3
                      LstNames.Items.Add(LstMat1.Items(num))
                      LstMat1.Items.Remove(LstMat1.Items(num))
                      num = num - 1
                      If num = -1 Then
                          For fillLb = 0 To 3
                              LstMat1.Items.Insert(0, LstNames.Items(0))
                              LstNames.Items.Remove(LstNames.Items(0))
                              num = 3
                          Next
                      End If
                  Next
              End Sub
              
              Private Sub BtnMat2\_Click(sender As Object, e As EventArgs) Handles BtnMat2.Click
                  Static num = 3
                  For clearLb = 0 To 3
                      LstNames.Items.Add(LstMa
              
              CHill60C 1 Reply Last reply
              0
              • L Lost User

                MallardsReach wrote:

                So it shows, that sometimes, the best help is when your help yourself. And if it still proves difficult then visit a site that offers constructive help and advice.

                My advice remains unchanged, as well as the verdict, as non-typical use of common controls is confusing to typical end-users.

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                M Offline
                M Offline
                MallardsReach
                wrote on last edited by
                #9

                That's good to hear then, as I'm the only end user!

                L 1 Reply Last reply
                0
                • M MallardsReach

                  That's good to hear then, as I'm the only end user!

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #10

                  MallardsReach wrote:

                  That's good to hear then, as I'm the only end user!

                  Haha, in that case your helpdesk will be prepared for any questions from the users, and no problems handling complaints :D

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                  M 1 Reply Last reply
                  0
                  • L Lost User

                    MallardsReach wrote:

                    That's good to hear then, as I'm the only end user!

                    Haha, in that case your helpdesk will be prepared for any questions from the users, and no problems handling complaints :D

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                    M Offline
                    M Offline
                    MallardsReach
                    wrote on last edited by
                    #11

                    Eddy, you can always make me smile. :-D May not always understand the advice but always get the humour. (English Spelling)

                    1 Reply Last reply
                    0
                    • M MallardsReach

                      Hi Dave, I only ever code for myself, it's a hobby nothing more, this program is for the bowling club that I attend on Wednesday nights, we have 4 mats and when your game is finished the names of the 4 players go back in to the pool and the next 4 players use the mat you've just left. Below is the complete code, not that you need it but you can see what I did, no comments as it's only for me to play with.

                      Public Class Form1

                      Private Sub TextBox1\_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
                          If e.KeyCode = Keys.Enter Then
                              Static Fillup = 1
                              Select Case Fillup
                                  Case 1
                                      LstMat1.Items.Add(TextBox1.Text)
                                      TextBox1.Text = String.Empty
                                      If LstMat1.Items.Count = 4 Then
                                          Fillup = 2
                                      End If
                                  Case 2
                                      LstMat2.Items.Add(TextBox1.Text)
                                      TextBox1.Text = String.Empty
                                      If LstMat2.Items.Count = 4 Then
                                          Fillup = 3
                                      End If
                                  Case 3
                                      LstMat3.Items.Add(TextBox1.Text)
                                      TextBox1.Text = String.Empty
                                      If LstMat3.Items.Count = 4 Then
                                          Fillup = 4
                                      End If
                                  Case 4
                                      LstMat4.Items.Add(TextBox1.Text)
                                      TextBox1.Text = String.Empty
                                      If LstMat4.Items.Count = 4 Then
                                          Fillup = 5
                                      End If
                                  Case 5
                                      LstNames.Items.Add(TextBox1.Text)
                                      TextBox1.Text = String.Empty
                              End Select
                          End If
                      End Sub
                      
                      Private Sub BtnMat1\_Click(sender As Object, e As EventArgs) Handles BtnMat1.Click
                          Static num = 3
                          For clearLb = 0 To 3
                              LstNames.Items.Add(LstMat1.Items(num))
                              LstMat1.Items.Remove(LstMat1.Items(num))
                              num = num - 1
                              If num = -1 Then
                                  For fillLb = 0 To 3
                                      LstMat1.Items.Insert(0, LstNames.Items(0))
                                      LstNames.Items.Remove(LstNames.Items(0))
                                      num = 3
                                  Next
                              End If
                          Next
                      End Sub
                      
                      Private Sub BtnMat2\_Click(sender As Object, e As EventArgs) Handles BtnMat2.Click
                          Static num = 3
                          For clearLb = 0 To 3
                              LstNames.Items.Add(LstMa
                      
                      CHill60C Offline
                      CHill60C Offline
                      CHill60
                      wrote on last edited by
                      #12

                      A gentle suggestion... Even though you are the only user, I still advise you to rename your textboxes to more meaningful names than the default TextBox1 - get into good habits :)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups