zoukankan      html  css  js  c++  java
  • [置顶] c# datagridview‘s learn

    c#   一串数字“1122331111155”,要输出到DataGridview控件上,但是要逐个数字读取,如果上一个数字与下一个相同,则排成一列,不相同,则另外排成一列。如“1122331111155”,输出的效果是,列一:11,列二:22,列三:33,列四:11111,列五:55。


    如下:

         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 DataGridViewColumn
                    {
                        CellTemplate = new DataGridViewTextBoxCell(),
                        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 DataGridViewColumn
                    {
                        CellTemplate = new DataGridViewTextBoxCell(),
                        Name = columnName
                    });
                });



  • 相关阅读:
    教你用笔记本充当无线路由,wifi上网了!!!
    SQL重复记录查询
    ==、object.Equals()、object.ReferenceEquals()
    SeriesChartType
    容易被忽视的装箱问题
    [转]Anonymous type and implicit type
    as、is、GetType()
    [转]dataGridView控件DateTime列插入DateTimePicker
    .NET(C#):理解值类型/引用类型,装箱/拆箱,Object类
    通过其轴标签沿 X 轴对齐不同系列中的数据点
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3201169.html
Copyright © 2011-2022 走看看