[02/03] How to work combobox with dataset for validation.
I would like to make a validation on my combobox,
i don't want to set combobox dropdownstyle to dropdownlist because dropdownlist unabled to let user find work inside the list by typing.
if user select the list do not contains on list. the combobox will became empty and errorprovider pop up.
thanksss
vb Code:
Private Sub ValidateComboItem(ByVal comboName As ComboBox)
Dim comparetext As String
If Not comboName.Text = String.Empty Then
Dim ItemFound As Boolean = False
For i As Integer = 0 To comboName.Items.Count - 1
If comboName.Items(i).ToString = comboName.Text Then
ItemFound = True
End If
Next
If Not ItemFound = True Then
comboName.Text = String.Empty
ErrorProvider1.SetError(comboName, "Value cannot find from list")
Else
ErrorProvider1.SetError(comboName, Nothing)
End If
ItemFound = False
End If
End Sub
Re: [02/03] How to work combobox with dataset for validation.
Perhaply My Explaination isn't clearly.
I say sorry about this >.<
Now i describe my problem again.
I got a combobox binded with dataset.
I don't want set the dropdownstyle of combobox to dropdownlist because dropdownlist setting cannot enable user to find the content from list via typing. However, i don't want let user keyin data into combobox that is not contain in combobox list. So I make the validation of combobox.
Normally, my coding above is work in normal, but that wasn't work in databinding of dataset.
How can i do that if dataset binding with combobox.
Thanks ... sorry for my bad english~~~
Re: [02/03] How to work combobox with dataset for validation.
I'm not sure exactly what's going on with your situation but are you sure you want to use comboboxes at all. Maybe you should use textboxes for data entry where the user has to type in every entry. Maybe you should sometimes use comboboxes and other times textboxes. I have a form that uses numerous comboboxes and on the form I have an explanation of the settings and I tell the user whether the dropdown list shows all valid entries which is sometimes the case or whether it's just a suggested list. Sometimes the possible entries are too numerous to list them all and in some cases for my program anyway there's only a few and then all valid entries are listed in the combobox dropdown list and I tell the user that this is the case.
Here's some code that I created to cut down on the amount of duplication in my program. It may not be the best. Someone suggested I should use TryParse but the code I used I understand perfectly so I went with it.
Code:
VR = TestStringDouble(ComboBoxVR.Text, 0) ' Example of function being used
Function TestStringDouble(ByVal ComboBoxString As String, ByVal ValueIfBlankOrNonnumeric As Double) As Double
If ComboBoxString = "" Or IsNumeric(ComboBoxString) = False Then
TestStringDouble = ValueIfBlankOrNonnumeric
Else
TestStringDouble = CType(ComboBoxString, Double)
End If
End Function
Function TestStringInteger(ByVal ComboBoxString As String, ByVal ValueIfBlankOrNonnumeric As Integer) As Integer
If ComboBoxString = "" Or IsNumeric(ComboBoxString) = False Then
TestStringInteger = ValueIfBlankOrNonnumeric
Else
TestStringInteger = CType(ComboBoxString, Integer)
End If
End Function
One function is used to check combobox entries for variables that have been declared double and the other is used to check combobox entries for variables
that have been declared as integer. If a blank or non-numeric entry is made I may want to set the value to 0 or maybe some other number or else leave the variable set to whatever value it presently is and the functions allow for that. Hope I've been of some kind of help. If you want to get help on this site I humbly suggest that you improve your english.
Re: [02/03] How to work combobox with dataset for validation.
I agreed what you have suggested to improve my english, I will get help if my explaination is easy to understand.
American style is quite direct culture, but i like it ^ ^
Thanks for your help to me.
Hmm~~ Sir , i think you were misunderstood my situation.
I do not want to validate against declaration type of entries for variables.
Actually, i just want to allow user select record or data from my combobox list instead of key in. However, if I use dropdownlist style the data selection method is fixed means that user only can type the 1st character of record to select the record. Thus, forfeited to use dropdownlist.
I used dropdown as dropdownstyle. I set a limitation for user that do not allow select the data which do not contain in items list, if user do so the focus will lock combobox and invalid data would be clear.
I used the code i'm posting above, that's work fine if i do not user databinding with dataset. If i used databinding the return for
vb Code:
comboName.Items(i).Tostring
is 'System.Data.DataRowView instead of value in the combo items list.
Thanks sir to help me.