1
/// <summary>
2
/// 在ListView 控件中显示 DataTable的数据;
3
/// </summary>
4
public static void ShowDataInListView(DataTable dt,ListView lst )
5
{
6
lst.Clear();
7
// lst.View=System.Windows.Forms.View.Details;
8
lst.AllowColumnReorder = true;//用户可以调整列的位置
9
lst.GridLines=true;
10
11
int RowCount ,ColCount,i,j;
12
DataRow dr=null;
13
14
if(dt==null) return;
15
RowCount=dt.Rows.Count;
16
ColCount=dt.Columns.Count;
17
//添加列标题名
18
for(i=0;i<ColCount;i++)
19
{
20
lst.Columns.Add(dt.Columns[i].Caption.Trim(),lst.Width/ColCount,HorizontalAlignment.Left);
21
}
22
23
if(RowCount==0) return;
24
for(i=0;i<RowCount;i++)
25
{
26
dr=dt.Rows[i];
27
lst.Items.Add(dr[0].ToString().Trim());
28
for(j=1;j<ColCount;j++)
29
{
30
lst.Items[i].SubItems.Add((string)dr[j].ToString().Trim());
31
}
32
}
33
}
34

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34
