listView 绑定数据

       public static void ListView_Accessor(SqlDataReader dr, ListView listView)
        {
            try
            {
                while (dr.Read())
                {
                    ListViewItem ListDatas = new ListViewItem(dr[0].ToString());
                    if (dr.FieldCount > 0)
                    {
                        string[] DataList = new string[dr.FieldCount];
                        for (int i = 1; i < dr.FieldCount; i++)
                        {
                            DataList[i - 1] = dr[i].ToString();
                        }
                        ListDatas.SubItems.AddRange(DataList);
                    }
                    listView.Items.Add(ListDatas);
                }
            }
            catch
            { return; }
        }
posted @ 2009-12-17 16:09  睿德泽林  阅读(287)  评论(0编辑  收藏  举报