How to convert input form a checked list box into an index and have that index work across two forms?

StackOverflow https://stackoverflow.com/questions/14415433

سؤال

My checked list box has 200 thing that will need to be converted into an index. This index will have to work across two forms. So dealing the variable in a modular will be a logical action. However in the modular the checked list box does not exist and therefor i get an error. what im trying to achieve is to have colors change on selected text boxes wit hte flowing

Select Case Row
                Case 0
                    TxtA1.BackColor = Color.Red
                Case 1
                    TxtA2.BackColor = Color.Red
                Case 2
                    TxtA3.BackColor = Color.Red
                Case 3
                    TxtA4.BackColor = Color.Red
                Case 4
                    TxtA5.BackColor = Color.Red
               ...
               case 200
                    TxtB67.BackColor = Color.Red
                  end select 
هل كانت مفيدة؟

المحلول

1.) In a module, you can access all forms and its public members, e. g. with Form1.CheckedListBox1. Or Form1.Controls("CheckedListBox1")
2.) When programmers do monotonous, repetitive work over 201 cases, something is wrong. You should think of another way to map the checked indices with those labels. You can use the name itself or the Tag property to iterate over them (e. g. Form1.Controls("txtColored_" & i.ToString) in a loop) (although there are still much better solutions, depending on the details of your design).
3.) You might probably want to reset the color from a Label if it is not selected, in this case you will have to set the color for every Label in each of the 201 cases.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top