0

我正在开发一个应用程序,我需要打印从数据库中获取的列表视图的内容。我已成功显示列表视图,但我需要在报告中添加支付总金额的聚合分组并查看它。我已经这样做了(来自我的查询..但我需要这些数据在“最后两个”下列表视图的列而不是前两个。此外,我还希望这些项目居中,并希望字体为粗体。我该如何实现这一点。以下是我到目前为止的代码:

           //setting up command 
            OdbcCommand commandSql = new OdbcCommand("SELECT stateid,surname,firstname,amount FROM scheduledpayment", _connection);
            OdbcDataReader odr = commandSql.ExecuteReader();
            while (odr.Read())
            {
                ListViewItem item = new ListViewItem(odr["stateid"].ToString());
                item.SubItems.Add(odr["surname"].ToString());
                item.SubItems.Add(odr["firstname"].ToString());
                item.SubItems.Add(odr["amount"].ToString());
                listView1.Items.Add(item);
            }
             OdbcCommand commandSql2 = new OdbcCommand("SELECT sum(amount) amount FROM scheduledpayment", _connection);
            OdbcDataReader odr2 = commandSql2.ExecuteReader();
            while (odr2.Read())
            {
                ListViewItem item3 = new ListViewItem("Total");
                item3.SubItems.Add(odr2["amount"].ToString());

                listView1.Items.Add(item3);
            }

输出是:

 ------------------------------------------------------------------------  


              200502317 BLACK   GRAY    15000
              200604572 BROWN   PURPLE  45000
              Total     789900

我怎样才能使列表视图的输出看起来像:

              200502317 BLACK   GRAY    15000
              200604572 BROWN   PURPLE  45000
                                Total  789900

谢谢。

4

1 回答 1

1

你应该使用

ListViewItem item3 = new ListViewItem("");
item3.SubItems.Add("");
item3.SubItems.Add("Total");
item3.SubItems.Add(odr2["amount"].ToString());
listView1.Items.Add(item3);
于 2012-06-14T05:46:54.700 回答