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
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to set 100 checkbox enable property according to values in a textfile ?

How to set 100 checkbox enable property according to values in a textfile ?

Scheduled Pinned Locked Moved Visual Basic
questioncsharphelptutorial
8 Posts 4 Posters 0 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.
  • A Offline
    A Offline
    anpm
    wrote on last edited by
    #1

    For a movie project(in vb.net 2005), i have to store the availabilty of seat (100 checkboxes) in a textfile.According to the value of textfile like "True" or "false" ,i have to make the enable property of checkbox as enabled or disabled.The checkboxes are named as A1,A2,A3,..,A10 B1,B2..B10.Can anyone help me for this question ?

    R T 2 Replies Last reply
    0
    • A anpm

      For a movie project(in vb.net 2005), i have to store the availabilty of seat (100 checkboxes) in a textfile.According to the value of textfile like "True" or "false" ,i have to make the enable property of checkbox as enabled or disabled.The checkboxes are named as A1,A2,A3,..,A10 B1,B2..B10.Can anyone help me for this question ?

      R Offline
      R Offline
      reegan41
      wrote on last edited by
      #2

      What kind of format is this textfile set up in? In other words, how are you determining whether the checkbox control should be enabled to true or false?

      A 1 Reply Last reply
      0
      • R reegan41

        What kind of format is this textfile set up in? In other words, how are you determining whether the checkbox control should be enabled to true or false?

        A Offline
        A Offline
        anpm
        wrote on last edited by
        #3

        Thanks. The textfile is in the format of T;T;F;T;T;T;T;T;F;T .This pattern in ten rows. "T" stands for true (that is that seat is available for booking) and "f" for false .

        R 1 Reply Last reply
        0
        • A anpm

          Thanks. The textfile is in the format of T;T;F;T;T;T;T;T;F;T .This pattern in ten rows. "T" stands for true (that is that seat is available for booking) and "f" for false .

          R Offline
          R Offline
          reegan41
          wrote on last edited by
          #4

          Set up a counter to count the rows in your text file (this number should be incremented each time your text file goes to the next row when reading it) Set up an index that will represent each seat when going through the row. Loop through each row character by character, and have if statements checking whether its true or false When looping, have if statements that will check the row count, and assign that to an alphabetic character representing your checkbox. ie. when rowcount is 1, it means A, 2, B, etc. The index for each character will let you know which checkbox you are referring to. So if you're in rowcount 1, and your loop index is currently at 5 (i=5) or something, then you know you're dealing with control A5...once that is verified is just a simple call like A5.Enabled = True, or A5.Enabled = False, depending on if the character you are checking was T or F.

          A 1 Reply Last reply
          0
          • R reegan41

            Set up a counter to count the rows in your text file (this number should be incremented each time your text file goes to the next row when reading it) Set up an index that will represent each seat when going through the row. Loop through each row character by character, and have if statements checking whether its true or false When looping, have if statements that will check the row count, and assign that to an alphabetic character representing your checkbox. ie. when rowcount is 1, it means A, 2, B, etc. The index for each character will let you know which checkbox you are referring to. So if you're in rowcount 1, and your loop index is currently at 5 (i=5) or something, then you know you're dealing with control A5...once that is verified is just a simple call like A5.Enabled = True, or A5.Enabled = False, depending on if the character you are checking was T or F.

            A Offline
            A Offline
            anpm
            wrote on last edited by
            #5

            Thanks. Still i am not getting how i can retrieve the name of checkbox. How i get (name of checkbox).enabled.i have 100 checkboxes to change their enable property.I am stuck here . My code is like this Friend spider1Seat(9, 9) As String Dim rowNames() As String = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"} Dim colNames() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} Private Sub lstSessionTime_SelectedIndexChanged Dim row As Integer Dim col As Integer Dim readArray() As String row = .cboMovieName.SelectedIndex col = .lstSessionTime.SelectedIndex If row = 0 And col = 0 Then seatReader = New StreamReader("Spider1Seat.txt") Do While seatReader.Peek <> -1 readArray = Split(seatReader.ReadLine, ";") For ctr2 As Integer = 0 To rownames.length-1 spider1Seat(ctr, ctr2) = readArray(ctr2) If spider1Seat(ctr, ctr2) = "T" Then End If Next ctr += 1 Loop End If

            B 1 Reply Last reply
            0
            • A anpm

              Thanks. Still i am not getting how i can retrieve the name of checkbox. How i get (name of checkbox).enabled.i have 100 checkboxes to change their enable property.I am stuck here . My code is like this Friend spider1Seat(9, 9) As String Dim rowNames() As String = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"} Dim colNames() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} Private Sub lstSessionTime_SelectedIndexChanged Dim row As Integer Dim col As Integer Dim readArray() As String row = .cboMovieName.SelectedIndex col = .lstSessionTime.SelectedIndex If row = 0 And col = 0 Then seatReader = New StreamReader("Spider1Seat.txt") Do While seatReader.Peek <> -1 readArray = Split(seatReader.ReadLine, ";") For ctr2 As Integer = 0 To rownames.length-1 spider1Seat(ctr, ctr2) = readArray(ctr2) If spider1Seat(ctr, ctr2) = "T" Then End If Next ctr += 1 Loop End If

              B Offline
              B Offline
              Benjamin Liedblad
              wrote on last edited by
              #6

              Dim cb As CheckBox = CType(Me.Controls.Find("A1", True)(0), CheckBox) cb.Checked = True

              A 1 Reply Last reply
              0
              • A anpm

                For a movie project(in vb.net 2005), i have to store the availabilty of seat (100 checkboxes) in a textfile.According to the value of textfile like "True" or "false" ,i have to make the enable property of checkbox as enabled or disabled.The checkboxes are named as A1,A2,A3,..,A10 B1,B2..B10.Can anyone help me for this question ?

                T Offline
                T Offline
                Tom Deketelaere
                wrote on last edited by
                #7

                first you would have to read the text file and for every line in the text file (wich I assumse corrisponds with the letter (line1=A, line2=B)) you dynamicly enable or disable the checkbox this is how I did it (made a little example but can't attach it here so just the code then) its only for 2 rows but should work fine for how many you want (remember I made it in 5 min so there are things that could be better) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim fs As New System.IO.StreamReader("C:\Documents and Settings\Tom\Mijn documenten\test.txt") Dim rows As New List(Of String) rows.Add("A") rows.Add("B") Dim row As Integer = 0 Do While Not fs.EndOfStream Dim s() As String = fs.ReadLine.Split(";") Dim column As Integer = 1 Do While column < s.Length + 1 enabledisableseat(rows.Item(row), column, IIf(s(column - 1).Equals("T"), True, False)) column += 1 Loop row += 1 Loop End Sub Private Sub enabledisableseat(ByVal row As String, ByVal column As Integer, ByVal enable As Boolean) For Each c As Control In Me.Controls If c.GetType.Equals(GetType(CheckBox)) Then Dim chk As CheckBox = c If chk.Name.Equals(row & column) Then chk.Enabled = enable End If End If Next End Sub I hope this helps you on your way

                1 Reply Last reply
                0
                • B Benjamin Liedblad

                  Dim cb As CheckBox = CType(Me.Controls.Find("A1", True)(0), CheckBox) cb.Checked = True

                  A Offline
                  A Offline
                  anpm
                  wrote on last edited by
                  #8

                  Thank you everyone.I got the logic form u people.It worked.

                  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