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.