The custom control comboboxedit and repositoryitemcombobox of devexpress enables display by alphabet

Source: Internet
Author: User

Modify the control by yourself to query by the combination of the first letter of the data of the query item. Support for ComboBox, comboboboxedit, repositoryitemcombobox,

 

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. drawing;
Using system. componentmodel;
Using system. Windows. forms;
Using devexpress. xtraeditors;
Using devexpress. xtraeditors. repository;
Using devexpress. xtraeditors. registrator;
Using devexpress. xtraeditors. drawing;
Using devexpress. xtraeditors. viewinfo;
Using devexpress. xtraeditors. Popup;
Using system. collections;

Namespace chinese2spell
{
// The attribute that points to the Registration Method
[Userrepositoryitem ("registercustomedit")]
Public class repositoryitemcustomcomboboxedit: repositoryitemcombobox {

// The static constructor which callthe Registration Method
Static repositoryitemcustomcomboboxedit () {registercustomedit ();}

// Initialize New Properties
Public repositoryitemcustomcomboboxedit (){
}

// The unique name for the custom Editor
Public const string customeditname = "customcomboboxedit ";

// Return the unique name
Public override string editortypename {get {return customeditname ;}}

// Register the editor
Public static void registercustomedit (){
// Icon representing the editor within a container editor's designer
Editorregistrationinfo. default. editors. add (New editorclassinfo (customeditname, typeof (customcomboboxedit), typeof (bytes), typeof (comboboxviewinfo), new buttoneditpainter (), true, null, typeof (devexpress. accessibility. popupeditaccessible )));
}
}

Public class customcomboboxedit: comboboxedit {
Protected override devexpress. xtraeditors. Popup. popupbaseform createpopupform (){
Return new custompopuplistboxform (this );
}
// The static constructor which callthe Registration Method
Static customcomboboxedit () {repositoryitemcustomcomboboxedit. registercustomedit ();}

// Initialize the new instance
Public customcomboboxedit (){
//...
}

Private arraylist m_list = new arraylist ();
Protected override void onenter (eventargs E)
{
M_list.clear ();
M_list.addrange (this. properties. items );
Base. onenter (E );
}

Protected override void onleave (eventargs E)
{
This. properties. Items. Clear ();
This. properties. Items. addrange (m_list.toarray ());
Base. onleave (E );
}

Protected override void ontextchanged (eventargs E)
{
If (this. Text! = "")
{
While (this. properties. Items. Count> 0)
{
This. properties. Items. removeat (0 );
}
Foreach (Object o in this. m_list)
{
If (getchinesespell (O. tostring (). tolower (). Contains (this. Text. tolower ()))
{
This. properties. Items. Add (O );
}
}
}
This. properties. Items. Add ("231 ");
This. properties. showdropdown = devexpress. xtraeditors. Controls. showdropdown. singleclick;
This. showpopup ();
//. Droppeddown = true;
This. cursor = cursors. default;
Base. ontextchanged (E );
// Base. ontextupdate (E );
}

Static Public String getchinesespell (string strtext)
{
Int Len = strtext. length;
String mystr = "";
For (INT I = 0; I <Len; I ++)
{
Mystr + = getspell (strtext. substring (I, 1 ));
}
Return mystr;
}

Static Public String getspell (string cnchar)
{
Byte [] arrcn = encoding. Default. getbytes (cnchar );
If (arrcn. length> 1)
{
Int area = (short) arrcn [0];
Int Pos = (short) arrcn [1];
Int code = (area <8) + Pos;
Int [] areacode = {45217,452 53, 45761,463 18, 46826,470 10, 47297,476 14, 48119,481 19, 49062,493 24, 49896,503 71, 50614,506 22, 50906,513 87, 51446,522 18, 52698,526 98, 52698,529 80, 53689,544 81 };
For (INT I = 0; I <26; I ++)
{
Int max = 55290;
If (I! = 25) max = areacode [I + 1];
If (areacode [I] <= Code & Code <max)
{
Return encoding. Default. getstring (New byte [] {(byte) (65 + I )});
}
}
Return "*";
}
Else
Return cnchar;
}

// Return the unique name
Public override string editortypename {get {return repositoryitemcustomcomboboxedit. customeditname ;}}

// Override the properties property
// Simply type-cast the object to the custom repository item type
[Designerserializationvisibility (designerserializationvisibility. Content)]
Public new repositoryitemcustomcomboboxedit properties {
Get {return base. properties as repositoryitemcustomcomboboxedit ;}
}

}

Public class custompopuplistboxform: popuplistboxform {
Public custompopuplistboxform (comboboxedit be)
: Base (be ){

}
Protected override popuplistbox createlistbox (){
Return new custompopuplistbox (this );
}

}

Public class custompopuplistbox: popuplistbox {
Public custompopuplistbox (popuplistboxform owner)
: Base (owner ){
}
Protected override basestylecontrolviewinfo createviewinfo (){
Return new custombasestylecontrolviewinfo (this );
}
}

Public class custombasestylecontrolviewinfo: popuplistboxviewinfo {
Public custombasestylecontrolviewinfo (popuplistbox owner)
: Base (owner ){
}
// Protected override baselistboxviewinfo. iteminfo createiteminfo (rectangle bounds, object item, string text, int index ){
// If (item. tostring ()! = "1") {text = "" + text ;}
// Return base. createiteminfo (bounds, item, text, index );
//}
}
}

 

 

 

Actual call: instantiate the control first and add the list item data:

 

Repositoryitemcustomcomboboxedit combox3 = new repositoryitemcustomcomboboxedit ();
Treelistcolumn1.columnedit = combox3;
Combox3.properties. Items. Add ("Beijing ");
Combox3.properties. Items. Add ("Beijing ");
Combox3.properties. Items. Add ("Shanghai ");
Combox3.properties. Items. Add ("Beijing ");
Combox3.properties. Items. Add ("Beijing ");
Combox3.properties. Items. Add ("Beijing ");
Combox3.properties. Items. Add ("Beijing ");
Combox3.properties. Items. Add ("Beijing ");
Combox3.properties. Items. Add ("Beijing ");
Combox3.properties. Items. Add ("Beijing ");
Combox3.properties. Items. Add ("Henan ");
Combox3.properties. Items. Add ("Hebei ");
Combox3.properties. Items. Add ("Tianjin ");
Combox3.properties. Items. Add ("tianchao ");

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.