Write query function TextBox

Source: Internet
Author: User

It mainly inherits the original TextBox; append number content (ValueText) and display content (DisplayText); after editing, query the database to bring up DisplayText (for example, name); and display it in the original TextBox; when the TextBox is edited, it displays ValueText (for example, number)

Of course, it can be further enhanced; for example, adding data dictionaries and adding all data of DataRow (to facilitate the updating of other components based on the record set during development ).

The running effect is as follows:

Main Code:

1. inherit Components

public partial class TTextBox : Infragistics.Win.UltraWinEditors.UltraTextEditor

2. Define attributes

        private string displayMember;        public string DisplayMember { get { return displayMember; } set { displayMember = value; } }        private string valueMember;        public string ValueMember { get { return valueMember; } set { valueMember = value; } }        private int max_Length;        public int Max_Length { get { return max_Length; } set { max_Length = value; } }

3. original component events, and additional code

 protected override void OnEndInit()        {            base.OnEndInit();            max_Length = base.MaxLength;                    }        protected override void OnBeforeEnterEditMode(CancelEventArgs e)        {            base.OnBeforeEnterEditMode(e);            if (valueMember == null)                valueMember = "";            if (max_Length != null && max_Length != 0)                base.MaxLength = max_Length;            base.Value = valueMember;                              }        protected override void OnEnter(EventArgs e)        {            base.OnEnter(e);            base.SelectAll();        }        protected override void OnAfterExitEditMode(EventArgs e)        {            base.OnAfterExitEditMode(e);            if (displayMember == null)                displayMember = "";            base.MaxLength = 0;            base.Value = displayMember;        }
protected override void OnValueChanged(EventArgs e)        {                       base.OnValueChanged(e);            if (base.Value == null)                return;            valueMember = base.Value.ToString();            //maxLength = base.MaxLength;            DisplayMember = GetValue("select Name from Table");                        if (DisplayMember == "")                valueMember = "";            else                DisplayMember = DisplayMember+ "(" + valueMember + ")";        }

The running effect is as follows:

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.