Hi, using VB 2010 with VS.
I have around 200 fields in a database, represented by text boxes on a form. A listview control is used to select a database record, after which the text boxes are populated with field values from that database record.
Most of the database fields are freetext or numeric and make sense to the user. However a subset of database fields have values in a specific range which do not make sense to a user.
For this subset, I have created combo boxes with user-friendly values in the items collection, and hidden the associated text boxes. I then use the .textchanged event to update the combo box with user-friendly values when their text boxes are are populated with field values from the database.
All textboxes share common .textchanged code, and I need a way to identify textboxes that are in the 'subset' that use combo boxes to display their data. I could add an 'if' statement and check the name, but this isn't very elegant. Instead I created a public control collection, and add each of the textboxes in the subset to the collection when the form loads. Then in the .textchanged event, I check to see if 'sender' is in the control collection.
However I get an ambiguous error at runtime, which seems to indicate a problem with the first line (if referencedfields.contains(sender) then...)
declations;
form_load;
.textchanged event
Is there a better way to do this?
I have around 200 fields in a database, represented by text boxes on a form. A listview control is used to select a database record, after which the text boxes are populated with field values from that database record.
Most of the database fields are freetext or numeric and make sense to the user. However a subset of database fields have values in a specific range which do not make sense to a user.
For this subset, I have created combo boxes with user-friendly values in the items collection, and hidden the associated text boxes. I then use the .textchanged event to update the combo box with user-friendly values when their text boxes are are populated with field values from the database.
All textboxes share common .textchanged code, and I need a way to identify textboxes that are in the 'subset' that use combo boxes to display their data. I could add an 'if' statement and check the name, but this isn't very elegant. Instead I created a public control collection, and add each of the textboxes in the subset to the collection when the form loads. Then in the .textchanged event, I check to see if 'sender' is in the control collection.
However I get an ambiguous error at runtime, which seems to indicate a problem with the first line (if referencedfields.contains(sender) then...)
declations;
Code:
public referencedfields as ControlCollectionCode:
With referencedfields
'these are the fields that use combo boxes to display data
.Add(tbID1)
.Add(tbID2)
.Add(tbID3)
.Add(tbID4)
.Add(tbtID5)
...
End WithCode:
If referencedfields.Contains(sender) Then
bLinkedEvents = False 'used to stop combobox .textchanged event
Dim linkedcombo As String = sender.name.replace("tb", "com") 'change control name from tb (textbox) to com (combobox)
Dim com As ComboBox = tabEdit.TabPages(1).Controls(linkedcombo)
com.Text = sender.text - 2 'data is offset
com.SelectedIndex = sender.text
bLinkedEvents = True
End IfIs there a better way to do this?