zoukankan      html  css  js  c++  java
  • listView绑定数据


            private void button1_Click(object sender, EventArgs e)
            {
                listView1.Items.Clear();
                listView1.Columns.Clear();
                SqlConnection con = new SqlConnection("server=.;database=pubs;user id=sa;password=123");
                con.Open();
                DataSet dst = new DataSet();
                SqlCommand cmd =new SqlCommand ("select title_id,type from titles",con );
                SqlDataAdapter dap = new SqlDataAdapter(cmd);
                dap.Fill(dst);
                con.Close();
                this.listView1.Columns.Add("ID编号", 80, HorizontalAlignment.Center);
                this.listView1.Columns.Add("类型", 80, HorizontalAlignment.Center);//增加列标题
                listView1.View = View.Details;
                listView1.GridLines = true;//显示网格线。。
                string[] str = new string[2];
                foreach (DataRow row in dst.Tables[0].Rows)
                {
                    str[0] = row["title_id"].ToString();
                    str[1] = row["type"].ToString();
                    ListViewItem item = new ListViewItem(str, 0);
                    listView1.Items.Add(item);
                }
            }
  • 相关阅读:
    python装饰器
    python名称空间和作用域
    python函数-函数对象
    python函数-参数
    python文件高级操作
    python基本文件操作
    python2和3的区别
    OSI-传输层
    Android屏幕density, dip等相关概念总结
    架构设计:系统间通信(20)——MQ:消息协议(下)
  • 原文地址:https://www.cnblogs.com/wantingqiang/p/1209925.html
Copyright © 2011-2022 走看看