一、让ListView控件显示表头的方法
在窗体中添加ListView 空间,其属性中设置:View属性设置为:Detail,Columns集合中添加表头中的文字。
二、利用代码给ListView添加Item。
首先,ListView的Item属性包括Items和SubItems。必须先实例化一个ListIteView对象。具体如下:
1
2
3
4
5
|
ListViewItem listViewItem= new ListViewItem(); listViewItem.SubItems[ 0 ].Text= "" 11111 ; //第一行第一例的值 listViewItem.SubItems.Add( "222" ); /// listViewItem.SubItems.Add( "222" ); ///以此类推 ListView1.Items.Add(listViewItem); |
三、Access中时间段查询的SQL语句书写规范(采用dateTimePick控件)
注意:# 是必须要加的
1
|
string sql=select * from tableName where timeField between # "+dateTimePick1.value.ToString()+" # and # "+dateTimePick2.vlaue.ToString()+" #"; |
四、连接数据库,按条件查询数据并显示在ListView中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
string path = System.Environment.CurrentDirectory + "\\database.mdb" ; OleDbConnection con = new OleDbConnection( "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path); //station2.mdb con.Open(); string sql = "select * from SendRecord where SENDTIME between #" + dateTimePicker1.Value.ToString() + "# and #" + dateTimePicker2.Value.ToString() + "#" ; // string sql = "select * from SendRecord"; OleDbDataAdapter da = new OleDbDataAdapter(sql, con); DataSet dt = new DataSet(); da.Fill(dt); DataTable dtb = dt.Tables[ 0 ]; foreach (DataRow row in dtb.Rows) { ListViewItem listviewItem = new ListViewItem(); listviewItem.SubItems.Clear(); listviewItem.SubItems[ 0 ].Text = string.Format( "{0:yyyy-MM-dd HH:mm}" , row[ "SENDTIME" ]); listviewItem.SubItems.Add((string)row[ "SENDER" ]); listviewItem.SubItems.Add((string)row[ "CONTENT" ]); listviewItem.SubItems.Add(string.Format( "{0}" , row[ "AUDITOR" ])); listviewItem.SubItems.Add(string.Format( "{0:yyyy-MM-dd HH:mm}" , row[ "AUDITTIME" ])); listviewItem.SubItems.Add(string.Format( "{0}" , row[ "AUDITSTATUS" ])); listView1.Items.Add(listviewItem); } con.Close(); } |
原文链接:http://www.cnblogs.com/dongteng/archive/2017/07/17/7197760.html