How to select multiple rows of the DataGrid at the same time

Source: Internet
Author: User

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.

 

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.