C # datagridview's learn

Source: Internet
Author: User

C # a string of numbers "1122331111155", which must be output to the DataGridview control, but must be read one by one. If the previous number is the same as the next one, it is arranged in a column, not the same, A column is also arranged. For example, "1122331111155", the output result is: Column 1: 11, column 2: 22, column 3: 33, column 4: 11111, column 5: 55. As follows: string numberStr = "1122331111155"; string temp = string. empty; string column = string. empty; List <string> lstColumn = new List <string> (); numberStr. toCharArray (). toList (). forEach (char c) =>{ if (string. isNullOrEmpty (temp) {temp = c. toString ();} if (temp = c. toString () {column + = c;} else {lstColumn. add (column); temp = c. toString (); column = temp ;}}); lstColumn. add (column); lstColumn. forEach (string columnName) => {this. dataGridView1.Columns. add (new maid (), Name = columnName}) ;}; MatchCollection mc = Regex. matches ("1122331111155 ",@"(.) \ 1 * "); List <string> columns = new List <string> (); foreach (Match m in mc) {columns. add (m. value);} columns. forEach (string columnName) => {this. dataGridView1.Columns. add (new maid (), Name = columnName });});

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.