How to set 100 checkbox enable property according to values in a textfile ?
-
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 ?
-
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 ?
-
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?
-
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 .
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.
-
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.
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
-
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
Dim cb As CheckBox = CType(Me.Controls.Find("A1", True)(0), CheckBox) cb.Checked = True
-
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 ?
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 -
Dim cb As CheckBox = CType(Me.Controls.Find("A1", True)(0), CheckBox) cb.Checked = True