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

C# 控制列表视图中项目的显示位置和外观,c#,C#,我正在开发一个应用程序,需要打印从数据库中获取的listview的内容。我已成功显示listview,但我需要在报告中添加支付总额的聚合分组并查看它。我已完成此操作(从我的查询中)。但我需要此数据位于“LAST TWO”下列表视图的列,而不是前两列。此外,我还希望这些项居中,并希望字体为粗体。如何实现这一点。以下是我迄今为止的代码: //setting up command OdbcCommand commandSql = new OdbcComm

我正在开发一个应用程序,需要打印从数据库中获取的listview的内容。我已成功显示listview,但我需要在报告中添加支付总额的聚合分组并查看它。我已完成此操作(从我的查询中)。但我需要此数据位于“LAST TWO”下列表视图的列,而不是前两列。此外,我还希望这些项居中,并希望字体为粗体。如何实现这一点。以下是我迄今为止的代码:

           //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
如何使listview的输出看起来像:

              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);

谢谢..这很有效..你知道如何将项目左右对齐并使字体显示粗体吗?@ewom2468:对于listview中的每一列,你都可以决定对齐方式(这是一个属性)。我想使用不同的字体(但我不确定)您必须手动管理重绘…@ewom2468:如果您使用WinForms,您在ListView中声明了四列;好的,打开第四列的属性,您将在那里找到一个可以设置为使文本正确对齐的属性。我做到了……它只会更改标题文本的对齐方式……而不会更改项目文本的对齐方式