我正在开发一个应用程序,我需要打印从数据库中获取的列表视图的内容。我已经成功显示了列表视图,但是我需要在报告中添加总支付金额的聚合分组并查看它。我已经完成了这个(从我的查询...但我需要这个数据在“最后两个”之下列表视图的列,而不是前两个。此外,我还希望这些项目居中,并希望字体为粗体。我如何实现这一点。以下是我的代码:
//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);
}
而OutPut是:
------------------------------------------------------------------------
200502317 BLACK GRAY 15000
200604572 BROWN PURPLE 45000
Total 789900
如何使listview的输出看起来像:
200502317 BLACK GRAY 15000
200604572 BROWN PURPLE 45000
Total 789900
感谢。
答案 0 :(得分:1)
你应该使用
ListViewItem item3 = new ListViewItem("");
item3.SubItems.Add("");
item3.SubItems.Add("Total");
item3.SubItems.Add(odr2["amount"].ToString());
listView1.Items.Add(item3);