控制列表视图中项目的显示位置和外观



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

           //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

谢谢。

你应该

使用

ListViewItem item3 = new ListViewItem("");
item3.SubItems.Add("");
item3.SubItems.Add("Total");
item3.SubItems.Add(odr2["amount"].ToString());
listView1.Items.Add(item3);

最新更新