码迷,mamicode.com
首页 > 其他好文 > 详细

ListView绑定正确姿势

时间:2015-01-01 13:38:19      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

 //加载
        private void button2_Click_1(object sender, EventArgs e)
        {
            listView1.Items.Clear();
            listView1.Columns.Clear();
            SqlConnection con = new SqlConnection("server=.;database=t5;user id=sa;password=123");
            con.Open();
            DataSet dst = new DataSet();
            SqlCommand cmd = new SqlCommand("select ID,Format,Cotegory,Place,Star,Name,director,Price,Number from AaA", 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);//增加列标题
            this.listView1.Columns.Add("类型", 80, HorizontalAlignment.Center);
            this.listView1.Columns.Add("产地", 80, HorizontalAlignment.Center);//增加列标题
            this.listView1.Columns.Add("主演", 80, HorizontalAlignment.Center);
            this.listView1.Columns.Add("音像名称", 80, HorizontalAlignment.Center);//增加列标题
            this.listView1.Columns.Add("导演", 80, HorizontalAlignment.Center);
            this.listView1.Columns.Add("价格", 80, HorizontalAlignment.Center);//增加列标题
            this.listView1.Columns.Add("库存数量", 80, HorizontalAlignment.Center);

            listView1.View = View.Details;
            listView1.GridLines = true;//显示网格线。。
            string[] str = new string[9];

            foreach (DataRow row in dst.Tables[0].Rows)
            {
                str[0] = row["ID"].ToString();
                str[1] = row["Format"].ToString();
                str[2] = row["Cotegory"].ToString();
                str[3] = row["Place"].ToString();
                str[4] = row["Star"].ToString();
                str[5] = row["Name"].ToString();
                str[6] = row["director"].ToString();
                str[7] = row["Price"].ToString();
                str[8] = row["Number"].ToString();
                ListViewItem item = new ListViewItem(str, 0);
                listView1.Items.Add(item);


            }

ListView绑定正确姿势

标签:

原文地址:http://www.cnblogs.com/xiaz/p/4197170.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!