Combobox -- onLoadSuccess usage example, vbcombobox usage

Source: Internet
Author: User

Combobox -- onLoadSuccess usage example, vbcombobox usage

I wonder if you have found out that in the article on Cascade Implementation of combobox in easyUI

When setting combobox, I wrote an onLoadSuccess function.

This function is triggered after the remote data is loaded successfully. It can be divided into the following situations:

1. If it is not limited by onBeforeLoad, it will be triggered once during initialization regardless of the method used, because onBeforeLoad will be triggered once in any case during initialization.

2. If it is not restricted by onBeforeLoad, when data is loaded in remote mode, each request is triggered once the data is successfully received.


The onLoadSuccess function I wrote previously aims to trigger onLoadSuccess to load and translate the cascade combobox values when the primary combobox loads data and translates the data.

Because the cascade combobox is completely passive, we trigger it in the onSelect function when we create a new one, and onLoadSuccess is required for modification.

Let's take a look at my previous statements:

     onLoadSuccess:function(){     var value = $(this).combobox('getValue');     if(value != ''){    <span style="white-space:pre"></span>$('[comboname=city]').combobox('reload', 'test/getCityListByProvince?id=' + $(this).combobox('getValue'));    }     }

Here, we first determine whether there is a value in the main combobox. If there is a value, we load the data in the cascade combobox for translation.


Is there any problem?

This does not seem to be a problem for the drop-down selection box of editable: false, because the value must be the corresponding value instead of the other mess.

However, if the prompt function of combobox is implemented like in the previous article, it seems that there are some problems.


For example, when we enter a keyword, each keyword will trigger onLoadSuccess, and the value also has a value, and that is the value you entered (but here I personally feel that the design of combobox is a bit problematic, because the input value should be used as text, and the value should be blank before the select Operation)

In this way, there will be many more incorrect requests, because the cascade request only needs to be triggered during onSelect.


So how can we improve it? Add a judgment condition.

Solution 1: if ($ (this). combobox ('getvalue') =$ (this). combobox ('gettext') {return}

It seems feasible, but in fact, when the input speed is too fast, the two values will be different! The reason is not further explored. Give up.

Solution 2: because the values used here are numbers, you can use a regular expression to determine

If (/^ \ d + $ /. test (value). This method is feasible for the moment, but not perfect. When a user enters a number, it triggers a keyword search, so no result is obtained.

Solution 3: onBeforeLoad can be used to determine

OnBeforeLoad: function (param) {if (param = null | param. q = null | param. q. replace (// g, '') ='') {var value = $ (this ). combobox ('getvalue'); if (value) {// here it can be determined to be modified, where the data param in the cascade combobox is loaded. id = value; return true;} return false ;}}
Both solution 2 and solution 3 can achieve the goal ~


Usage of Combobox in VB

Use the ComboBox component
You can use the ComboBox component in any form or application that needs to be selected from the list. For example, you can provide a State/province drop-down list in the customer address form. For complex cases, you can use an editable combo box. For example, in a driving direction application, you can use an editable combo box to allow users to enter the departure address and target address. The drop-down list can contain addresses that you have previously entered.

ComboBox Parameters
The following are the creation parameters you can set for each ComboBox component in the property checker or in the component checker panel:

Editable: Determine whether the ComboBox component is editable (true) or optional (false ). The default value is false.

Labels fills the ComboBox component with an array of text values.

Data associates a data value with each item in the ComboBox component. This data parameter is an array.

RowCount sets the maximum number of items that can be displayed at a time without using the scroll bar. The default value is 5.

You can write an Action Script to set other options of a ComboBox instance by using methods, attributes, and events of the ComboBox class. For more information, see ComboBox class.

Create an application with the ComboBox component
The following process explains how to add the ComboBox component to an application during creation. In this example, the combo box shows a list of cities selected from the drop-down list.

To create an application with the ComboBox component, perform the following operations:
Drag the ComboBox component from the "component" panel to the stage.
Select the "deformation" tool and resize the component on the stage.
The combo box can only be resized on the stage during creation. Generally, you only need to change the width of the combo box to adapt to its entries.

Select the combo box and enter the Instance name comboBox in the property checker.
On the component checker panel or in the property checker, perform the following operations:
Enter minneapois, Portland, and Keene as the tag parameters. Double-click the tag parameter field to open the "value" dialog box. Click the plus sign (+) to add a project.
Enter mn.swfw.or.swf and NH.swf as data parameters.
These are hypothetical SWF files. For example, if you select a city in the combo box, you can load these files.

Select the first frame in the timeline, open the action panel, and enter the following code:
Form = new Object ();
Form. change = function (evt ){
Trace(evt.tar get. selectedItem. label );
}
ComboBox. addEventListener ("change", form );

The last line of code adds the change event handler function to the ComboBox instance.

A usage of combobox in c #

You can try it just now. You should first create a new project, add a combobox and a label to the form, and then follow the instructions below. I think you should understand it, I can add QQ: 1200607

Private void Form1_Load (object sender, EventArgs e)
{
This. comboBox1.Items. Add ("");
This. comboBox1.Items. Add ("B ");
}

Private void combobox#selectedindexchanged (object sender, EventArgs e)
{
If (this. comboBox1.Text = "")
{
This. label1.Text = "1 ";
}
Else if (this. comboBox1.Text = "B ")
{
This. label1.Text = "2 ";
}

}

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.