Combobox automatically prompts the component to add the unselected item clearing function. combobox is cleared.

Source: Internet
Author: User

Combobox automatically prompts the component to add the unselected item clearing function. combobox is cleared.

This title is very difficult, but it is also a result of half a day. I'm sorry, the PE teacher.

The title is intended to express: As mentioned earlier, the combobox is used to implement the auto-Prompt component. However, it is stipulated that the component cannot save data that does not exist in the data.

The original idea was to use the onChange event for judgment, but in the auto-Prompt mode, this function triggers two onChange events every time it is changed, which is too strange to give up.

In addition, the onChange event is triggered every time the content in the combobox changes. This event is always triggered during the keyword input process.

What we need is to wait for the user to input the result for verification, so it does not meet the requirements.

The API finds that combo provides an onHidePanel event extension point, which is triggered when the automatic prompt box is hidden.

The idea at the time was: After the input is complete, the input box will certainly be hidden, and it can be regarded as an identifier for completing the input.

The test can basically meet the requirements. There is a small problem, that is, after the user quickly inputs and clicks somewhere else, after the combobox loses focus, it is possible that the input box will not be displayed. What about hiding?

Ah ~ It seems that the existing APIs cannot solve the problem perfectly, so you have to write it yourself .. But my front-end level is really not very good, blind j8 drum up a version, let's take a look ~

$. Extend ($. fn. combobox. methods, {completeCheck: function (jq) {var textbox = jq. combobox ('textbox '); console. log (jq) textbox. on ('blur', function () {setTimeout ('docompletecheck ("'+ jq. selector + '")', 200); // here let's take some operations in combobox})}; function doCompleteCheck (selector) {var jq =$ (selector ); var value = jq. combobox ('getvalue'); var json = jq. combobox ('getdata'); if (! FindInJson (json, value) {jq. combobox ('clear'); jq. combobox ('hidepanel ');}}

I added a new method for combobox: completeCheck

It is mainly to add an onBlur event to the textbox in combobox, which is the input component at the input time.

The doCompleteCheck function is triggered when the textbox loses focus, but some operations of combobox must be executed first.

Therefore, we gave a latency of MS, and then determined whether to clear the input values in combobox by comparing whether the values exist in data.

Here, we add that if the input content is not in data, the value of combobox ('getvalue') will be undefined, so this can also be determined.

It is just like calling other methods of combobox. $ ('# CC'). combobox ('completecheck ');



After you press a button, the items selected by the mouse in COMBOBOX are deleted from the list.

Combox. removeritem (combox. listindex) remembers this. Listindex indicates the selected row, and the mouse clicks must be selected. It is best to place the cursor in the double-click event.

How to clear the combobox drop-down list in vb without affecting the text in the input box

On the first floor, tianqing20wen extracts the value of 0th items, clears Combo1, and returns the value of 0th items to Combo1. Because the code execution speed is fast, we cannot see the changes, which can also meet the requirements of LZ. Below is my code, which directly deletes all items other than 0th items.
I hope this will help you. If you are satisfied, please adopt it. If you have any questions, please ask ^_^.

Private Sub commandementclick ()
Dim n As Integer
For n = Combo1.ListCount-1 To 0 Step-1
Combo1.RemoveItem n
Next n
End Sub

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.