Reputation: 841
I am developing an application where i will need to print the contents of a listview taken from a database. I have successfully displayed the listview,but i need to add an aggregate grouping of the total amount paid in the report and view it.I have done this(from my query..but i need this data to be under the "LAST TWO" columns of the listview and not the first two.In addition, i also want this items to be centered, and will want the font to be bold.How can i achieve this. Below is my code so far:
//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);
}
And The OutPut Is:
------------------------------------------------------------------------
200502317 BLACK GRAY 15000
200604572 BROWN PURPLE 45000
Total 789900
How can i make the output of the listview look like:
200502317 BLACK GRAY 15000
200604572 BROWN PURPLE 45000
Total 789900
Thanks.
Upvotes: 0
Views: 178
Reputation: 57573
You should use
ListViewItem item3 = new ListViewItem("");
item3.SubItems.Add("");
item3.SubItems.Add("Total");
item3.SubItems.Add(odr2["amount"].ToString());
listView1.Items.Add(item3);
Upvotes: 1