Winform dategridview is automatically completed.

Source: Internet
Author: User

1, first

 

CodeAs follows.

View code 1   Private Autocompletestringcollection autocompletesource =   New Autocompletestringcollection ();
2
3 Private   Void Datagridview1_editingcontrolshowing ( Object Sender, datagridvieweditingcontrolshowingeventargs E)
4 {
5 Datagridview dgv = (Datagridview) sender;
6 If (E. Control Is Textbox)
7 {
8 Textbox TB = (Textbox) E. Control;
9 If (Dgv. currentcell. owningcolumn. Name = " Name " )
10 {
11 TB. autocompletemode = Autocompletemode. suggestappend;
12 TB. autocompletesource = Autocompletesource. customsource;
13 TB. autocompletecustomsource =   This . Autocompletesource;
14 }
15 Else
16 {
17 TB. autocompletemode = Autocompletemode. None;
18 }
19 }
20 }
21
22 Private   Void Datagridviewcedatasourcechanged ( Object Sender, eventargs E)
23 {
24 VaR dgv = (Datagridview) sender;
25 This . Autocompletesource. Clear ();
26 Foreach (Maid R In Dgv. Rows)
27 {
28 String Val = R. cells [ " Name " ]. Value As   String ;
29 If ( ! String . Isnullorempty (VAL) &&   ! This . Autocompletesource. Contains (VAL ))
30 {
31 Autocompletesource. Add (VAL );
32 }
33 }
34 }
35
36 Private   Void Datagridview1_cellvalidating ( Object Sender, datagridviewcellvalidatingeventargs E)
37 {
38
39 }
40 // Add new members
41 Private   Void Maid ( Object Sender, datagridviewcelleventargs E)
42 {
43 Int I = 0 ;
44 If (E. rowindex =   - 1 )
45 {
46 I =   0 ;
47 }
48 Else
49 {
50 I = E. rowindex;
51 }
52 VaR dgv = (Datagridview) sender;
53 If (Dgv. Columns [E. columnindex]. Name =   " Name " )
54 {
55 String Val = Dgv [E. columnindex, I]. Value As   String ;
56 If ( ! String . Isnullorempty (VAL) &&   ! This . Autocompletesource. Contains (VAL ))
57 {
58 Autocompletesource. Add (VAL );
59 }
60 }
61 }

 

The above steps can be used to automatically complete the implementation.

 

 

 

 

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.