Results 1 to 4 of 4

Thread: [02/03] How to work combobox with dataset for validation.

  1. #1

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    [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:
    1. Private Sub ValidateComboItem(ByVal comboName As ComboBox)
    2.         Dim comparetext As String
    3.         If Not comboName.Text = String.Empty Then
    4.             Dim ItemFound As Boolean = False
    5.             For i As Integer = 0 To comboName.Items.Count - 1
    6.  
    7.  
    8.                 If comboName.Items(i).ToString = comboName.Text Then
    9.                     ItemFound = True
    10.                 End If
    11.             Next
    12.             If Not ItemFound = True Then
    13.                 comboName.Text = String.Empty
    14.                 ErrorProvider1.SetError(comboName, "Value cannot find from list")
    15.             Else
    16.                 ErrorProvider1.SetError(comboName, Nothing)
    17.             End If
    18.             ItemFound = False
    19.         End If
    20.  End Sub
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  2. #2

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    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~~~
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  3. #3
    Fanatic Member EntityX's Avatar
    Join Date
    Feb 2007
    Location
    Omnipresence
    Posts
    798

    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.
    Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.

    "Persistence is the magic of success." Paramahansa Yogananda

  4. #4

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    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:
    1. comboName.Items(i).Tostring
    is 'System.Data.DataRowView instead of value in the combo items list.

    Thanks sir to help me.
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width