C # DataGridView operations,

Source: Internet
Author: User

C # DataGridView operations,

1 # region Operation DataGridView 2 3 // <summary> 4 // initialize the DataGridView attribute 5 /// </summary> 6 // <param name = "dg"> the DataGridView dview to be processed </param> 7 // <param name = "allowUserToAddRows"> allow users to Add rows </param> 8 /// <param name = "allowUserToDeleteRows"> allow users to delete rows </param> 9 // <param name = "rowHeadersVisible"> whether to display columns containing row titles </param> 10 /// <param name = "columnHeadersHeightSizeMode "> column header height and size mode </param> 11 /// <param name =" multiSelect "> multiple selections </param> 12 /// <param name =" readOnly"> Read-Only </param> 13 // <param name = "rowHeadersWidth"> column header width </param> 14 // <param name = "selectionMode"> Column Selection mode </param> 15 public virtual void InitSetDataGridViewAttribute (datagridg dg, 16 bool allowUserToAddRows, 17 bool values, 18 bool values, 19 bool rowHeadersVisible, 20 rows visible, 21 bool multiSelect, 22 bool readOnly, 23 int rowHeadersWidth, 24 DataGridViewSelectionMode selectionMode) 25 {26 dg. allowUserToAddRows = allowUserToAddRows; 27 dg. allowUserToDeleteRows = allowUserToDeleteRows; 28 dg. allowUserToResizeRows = allowUserToResizeRows; 29 dg. rowHeadersVisible = rowHeadersVisible; 30 dg. columnHeadersHeightSizeMode = columnHeadersHeightSizeMode; 31 dg. multiSelect = multiSelect; 32 dg. readOnly = readOnly; 33 dg. rowHeadersWidth = rowHeadersWidth; 34 dg. selectionMode = selectionMode; 35 36 dg. rowStateChanged + = dg_RowStateChanged; 37} 38 39 // <summary> 40 // initialize the DataGridView attribute 41 // </summary> 42 // <param name = "dg"> dataGridView </param> 43 public virtual void InitSetDataGridViewAttribute (DataGridView dg) 44 {45 initsetdatagridviewattrimode (dg, 46 false, 47 false, 48 false, 49 true, DataGridViewColumnHeadersHeightSizeMode. autoSize, 50 false, 51 true, 52 50, 53 DataGridViewSelectionMode. fullRowSelect ); 54} 55 56 // <summary> 57 // 58 // </summary> 59 // <param name = "sender"> </param> 60/ // <param name = "e"> </param> 61 public virtual void dg_RowStateChanged (object sender, dataGridViewRowStateChangedEventArgs e) 62 {63 e. row. headerCell. value = (e. row. index + 1 ). toString (); 64} 65 66 // <summary> 67 // Add row 68 in the DataGridView /// </summary> 69 // <param name = "dg"> dataGridView </param> 70 // <param name = "dr"> added columns </param> 71 public void DataGridViewAddRows (DataGridView dg, dataGridViewRow dr) 72 {73 dg. rows. add (dr ); 74} 75 76 // <summary> 77 // Add column 78 in the DataGridView row // </summary> 79 // <param name = "objs"> Yes added object </param> 80 // <returns> column </returns> 81 public DataGridViewRow DataGridViewRowsAddCells (object [] objs) 82 {83 maid row = new maid (); 84 85 maid (object obj in objs) 86 {87 maid (); 88 tBoxCell. value = obj; 89 90 row. cells. add (tBoxCell); 91} 92 93 return row; 94} 95 96 // <summary> 97 // Add row 98 in the DataGridView /// </summary> 99 // <param name = "dg"> dataGridView </param> 100 // <param name = "listObjecArray"> List of added objects </param> 101 public void DataGridViewAddRows (DataGridView dg, list <object []> listObjecArray) 102 {103 foreach (object [] objs in listObjecArray) 104 {105 maid row dr = maid (objs); 106 107 maid (dg, dr ); 108} 109} 110 111 // <summary> 112 // Add row 113 in the DataGridView // </summary> 114 // <param name = "dg"> Yes the processed DataGridView </param> 115 // <param name = "objs"> added object </param> 116 public void DataGridViewAddRows (DataGridView dg, object [] objs) 117 {118 maid dr = maid (objs); 119 120 maid (dg, dr ); 121} 122 123 // <summary> 124 // DataGridView column sorting 125 // </summary> 126 // <param name = "dg"> dataGridView </param> 127 // <param name = "dataGridViewColumnIndex"> column index </param> 128 // <param name = "flag"> 0: ascending Order 1: Descending Order </param> 129 public void DataGridViewSort (DataGridView dg, int dataGridViewColumnIndex, int flag) 130 {131 switch (flag) 132 {133 case 0: 134 dg. sort (dg. columns [maid Index], ListSortDirection. ascending); 135 break; 136 case dg. sort (dg. columns [maid Index], ListSortDirection. descending); 138 break; 139 default: 140 break; 141} 142 143} 144 145 # endregion

 

Related Article

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.