前期准备1

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        void initLV(ListView l) 
        {
            l.MultiSelect = false;
            l.GridLines = true;
            l.FullRowSelect = true;
            l.View = View.Details;
        }

        void loadLV(ListView l,string sql) 
        {
            try
            {
                con.Open();
                SqlDataAdapter da=new SqlDataAdapter(sql,con);
                DataTable dt=new DataTable();
                da.Fill(dt);
                l.Items.Clear();
                l.Columns.Clear();
                int i,j;
                for (i = 0; i < dt.Columns.Count; i++)
                    l.Columns.Add(dt.Columns[i].Caption,(l.Width-4)/dt.Columns.Count);
                for (i = 0; i < dt.Rows.Count; i++) 
                {
                    ListViewItem li = new ListViewItem();
                    li.SubItems[0].Text=dt.Rows[i][0].ToString().Trim();
                    for(j=1;j

你可能感兴趣的:(前期准备1)