[★] ComboBox Experience summary [adding a piece of data statically after dynamically Binding data]

Source: Internet
Author: User

I. ComboBox Experience summary [adding a piece of data statically after dynamically Binding data]

Dropdowstyle = dropdown allows the user to enter the text box of the list item, which is the default value
Dropdownsysystemic = dropdownlist displays a list of items from which you can select

A: add an item in the property iItems

Cobshow. selectedindex index of the selected item
Cobshow. selecteditem Text of the selected item
Cobshow. selecttext Null Value
Cobshow. selectvalue error...
Cobshow. items [cobshow. selectedindex]. tostring () Text of the selected item

B: InProgramThe result of adding cobshow. item. Add () is the same as the above

C: a B. Both methods add the same result as above.

D: dynamically bind data

Cobshow. selectedindex index of the selected item
Cobshow. selecteditem system. datarow. defaultview
Cobshow. selecttext Null Value
Cobshow. selectvalue the value of the selected item
Text Value of the cobshow. Text Option
Cobshow. items [cobshow. selectedindex]. tostring () system. datarow. defaultview

E: If a value is written through the attribute or program, the original value will be cleared during dynamic binding.

F: if the data is dynamically bound, an error is reported through the program cobshow. item. Add ('zhi'). [the solution is as follows]
 
Fsubject is the text to be displayed, and ftech is the value to be passed

Datatable dt = cboshow. datasource as datatable;
Datarow DR = DT. newrow ();

Dr ["fsubject"] = "--- text ---";
Dr ["ftech"] = "--- value ---";

DT. Rows. insertat (DR, 0); insert to the first row
DT. Rows. Add (DR); append to the last row

Explanation: Dr ["fsubject"], Dr ["ftech"] is two columns in a row. After assigning values, add a complete row.
Cobshow. Text = "--- text ---", cobshow. selectvalue = "--- value ---"

Posted on Tianshan Han Xue reading (281) Comments (1) EDIT add to favorites reference network Abstract category: Technical Summary


Feedback:

# Re :[★] ComboBox Experience summary [adding a piece of data statically after dynamic binding] | Tianshan cold snow datatable dt = Ds. Tables [0];
Datarow DR = DT. newrow ();
Dr ["A"] = "0 ";
Dr ["B"] = "Please select ";
DT. Rows. insertat (DR, 0 );

Cboshow. datasource = Ds. Tables [0]; // The event is triggered at this time.
Cboshow. displaymember = "B"; // This event will also be triggered.
Cboshow. valuemember = "";

// The above is a very good method, but should I assign values one by one when there are multiple rows in the database?

// Let's continue with the discussion below. Will it trigger the event if there is an event selectindexchange in cboshow?

// Why do we need to discuss it, because sometimes we need to trigger the event instead of the event during loading, but instead, when selecting the event,

// We can see from the above that datasource will trigger an event during displaymember and will not trigger it in the future

// At this time, selectedvalue is always system. Data. datarowview; the value of selectvalue is determined directly in the event...

If (cboshow. selectedvalue. tostring ()! = "System. Data. datarowview ")
{
String cc = "111 ";

}
// [2]
// If (cboshow. Text! = "System. Data. datarowview ")
//{
// MessageBox. Show ("123 ");
//} Reply to more comments

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.