计算列表视图中的列

时间:2013-11-21 11:26:02

标签: c# listview

我是编程的新手,我在列表视图中有一个价目表,我想有另一个列一起计算最后一列和一个文本框,请指出正确的方向,因为我得到的方法和格式错误..这是我的代码:

listView1.Items.Clear();
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:xxxx;Persist Security Info=False");
OleDbCommand command = connection.CreateCommand();

if (comboBox1.Text == "Brickcom")
{
    ListViewItem li;
    command.CommandText = "SELECT [PartNo], [Category], [Product], [Resolution], [IncludedAccessories], [Price] FROM [Brickcom] WHERE ([Manufacturer] Like '" + comboBox1.Text.ToString() + "')";
    connection.Open();
    OleDbDataReader reader = command.ExecuteReader(CommandBehavior.Default);
    while (reader.Read())
    {
        listView1.Columns[0].Text = null;
        listView1.Columns[1].Text = null;
        listView1.Columns[2].Text = null;
        listView1.Columns[3].Text = null;
        listView1.Columns[4].Text = null;
        listView1.Columns[5].Text = null;
        listView1.Columns[6].Text = null;
        listView1.Columns[7].Text = null;
        listView1.Columns[8].Text = null;
        listView1.Columns[0].Text = "Part Number";
        listView1.Columns[1].Text = "Category";
        listView1.Columns[2].Text = "Product";
        listView1.Columns[3].Text = "Resolution";
        listView1.Columns[4].Text = "Included Accessories";
        listView1.Columns[5].Text = "Price";
        li = listView1.Items.Add(reader[0].ToString());
        li.SubItems.Add(reader[1].ToString());
        li.SubItems.Add(reader[2].ToString());
        li.SubItems.Add(reader[3].ToString());
        li.SubItems.Add(reader[4].ToString());
        li.SubItems.Add(reader[5].ToString());

        foreach (ListViewItem item in listView1.Items)
        {
            li.SubItems.Add(items[6].ToString());
            //listView1.Columns[6].Text = (Int32.Parse(textBox1.Text) * Int32.Parse(textBox2.Text)).ToString();
            item.SubItems[6].Text = (Int32.Parse(textBox1.Text) * Int32.Parse(textBox2.Text)).ToString();
        }

    }

    connection.Close();
}

0 个答案:

没有答案