zoukankan      html  css  js  c++  java
  • C#.NET 取数据到ListView

     public void SetListView(ListView lv, DataTable dt)
            {
                ListViewItem lvi;
                lv.Items.Clear();
                lv.Columns.Clear();
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    lv.Columns.Add(dt.Columns[i].Caption.ToString());
                }
                foreach (DataRow dr in dt.Rows)
                {
                    lvi = lv.Items.Add(dr[0].ToString());
                    for (int i = 1; i < dt.Columns.Count; i++)
                    {
                        lvi.SubItems.Add(dr[i].ToString());
                        if (lv.CheckBoxes == true && dr[i].ToString() == "Has")
                        {
                            lvi.Checked = true;
                        }
                    }
                }
                lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            }

          调用语句:SetListView(listView1,dt);

           

  • 相关阅读:
    LeetCode 79
    LeetCode 437
    LeetCode 783
    LeetCode 59
    LeetCode 每日一题 04/24
    LeetCode 5
    LeetCode 43
    简易多线程任务 往数据库插数据
    定时任务--查数据库--注解实现
    redis 简易 实现
  • 原文地址:https://www.cnblogs.com/cuishao1985/p/1343338.html
Copyright © 2011-2022 走看看