The DataGrid Control supports multi-row selection by default, but you need to press Ctrl to select multiple rows. By declaring three event handlers, we can directly select them without pressing CTRL. Add in sequence
Related Events
At the same time, you can create an arraylist to store the selected columns, because sometimes you may consider the selected columns, the last line to highlight is not necessarily the selected line.
The main code is as follows:
1 arraylist arraylistselectedrow = new arraylist ();
2 Private void maid (Object sender, eventargs E)
3 {
4 int CRI = maid;
5 datagrid1.select (CRI );
6 console. writeline ("in cell changed ");
7 datagrid1_click (sender, e );
8}
9 private void datagrid#click (Object sender, eventargs E)
10 {
11 int CRI = maid;
12 datagrid1.select (CRI );
13 console. writeline ("In click ");
14}
15 private void datagrid=mouseup (Object sender, mouseeventargs E)
16 {
17 int CRI = maid;
18 if (arraylistselectedrow. Contains (CRI ))
19 {
20 datagrid1.unselect (CRI );
21 arraylistselectedrow. Remove (CRI );
22}
23 else
24 {
25 datagrid1.select (CRI );
26
27 arraylistselectedrow. Add (CRI );
28}
29 for (INT I = 0; I <arraylistselectedrow. Count; I ++)
30 {
31 datagrid1.select (Int. parse (arraylistselectedrow [I]. tostring ()));
32}
33 console. writeline ("in mouse up ");
34}
35
In general, this can achieve the requirements, but it is troublesome. If you have a better solution, please leave a message to me.