• 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);
                }
            }
  • 相关阅读:
    centos pptp客户端 连接服务端
    工控上常见的通讯接口与协议
    winform无边框窗体拖动
    Winform实现窗体渐变色
    Win10系统安装
    WIN 10 系统能正常使用WLAN,无法连接以太网
    C#DataGridView分页显示数据
    遍历枚举的值
    C#dataGridView添加自增列
    Winform实现打印功能
  • 原文地址:https://www.cnblogs.com/wantingqiang/p/1209925.html
Copyright © 2020-2023  润新知