AutoComplete custom control in winform

Source: Internet
Author: User

This essay was supposed to have been published as early as two weeks ago, just because an error occurred while saving it after the last writing (not saved as a draft in advance). Sadly, I wrote it for half an hour.

AutoComplete is similar to Google search prompts. The implementation in winform is slightly different from that in web. Last year, I wrote a script class to adapt to AutoComplete on the web, but it was not pasted here. I would like to pay attention to the following points for this control:

1. Easy to call, without affecting the layout of the form during design;

2. Input prompts should support multiple positioning modes;

3. You need to adapt to different data extraction methods, such as specifying a able, specifying XML, and querying a database. Cache should be used to improve efficiency when necessary. Consider using the adapter idea to achieve good scalability.

Solution:

1. Let the custom control inherit from the component class rather than the control class. It can exist in the toolbox like the errorprovider control, but it does not occupy any position on the design interface;

2. There is nothing to say. Two attributes are made public. One is the positioning method, and the other is the parent container used for absolute positioning .;

3. Data Extraction and data presentation are separated. All data extraction adapters inherit from the ilistdataadapter interface, which declares the method: dataview getfitdata (string keyValue). In the future, we will add an extraction method, you only need to write an adapter.

TIPS:

1. By default, the order of elements stacked on the form is related to the order in the controls set, however. NET provides two good methods to place an element at the top or bottom: bringtofront, sendtoback

2. To make the datagridview control display an empty row when there is no data, you only need to set the attribute allowuseraddrows to true.

3. to specify the Row Height of the datgridview title during design, set columnheaderheightsizemode to enableresizing.

Check the running effect:

 

Download the source code and use example: AutoComplete of winform

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.