C# 将名称循环到listview C中

C# 将名称循环到listview C中,c#,C#,如果有人能帮我解决问题,我将无法在多个位置添加或插入项目“productname”。必须首先将其从当前位置删除或克隆 我试图在while循环中将产品名称添加到大部分图像中。您不断更改item.Text的值,然后迭代所有图像,但添加相同的项目值 ListViewItem item = new ListViewItem(); string productname = ""; conn = new MySqlConnection(); conn.ConnectionString = connStrin

如果有人能帮我解决问题,我将无法在多个位置添加或插入项目“productname”。必须首先将其从当前位置删除或克隆


我试图在while循环中将产品名称添加到大部分图像中。

您不断更改item.Text的值,然后迭代所有图像,但添加相同的项目值

ListViewItem item = new ListViewItem();
string productname = "";
conn = new MySqlConnection();
conn.ConnectionString = connString;
conn.Open();
string queryssxxxqbb = "Select * from products where deleted='No'";
MySqlCommand cmdaaxxxqbb = new MySqlCommand(queryssxxxqbb, conn);
MySqlDataReader dataReaderxxxxxqbb = cmdaaxxxqbb.ExecuteReader();
while (dataReaderxxxxxqbb.Read())
{

    productname = dataReaderxxxxxqbb["productname"].ToString();
    string productprice = dataReaderxxxxxqbb["productprice"].ToString();
    string picturelink = dataReaderxxxxxqbb["picturelink"].ToString();

    try
    {
        this.imageList1.Images.Add(Image.FromFile(@"\\" + 
            Properties.Settings.Default.Local_Server + 
            "\\Documents\\Stock And Inventory Software\\Product Pictures\\" +
            picturelink));

    }
    catch
    {
        this.imageList1.Images.Add(Properties.Resources.default_image);
    }

    this.listView1.View = View.LargeIcon;
    this.imageList1.ImageSize = new Size(100, 90);
    this.listView1.LargeImageList = this.imageList1;        

    item.Text = productname;

}
conn.Close();

for (int j = 0; j < this.imageList1.Images.Count; j++)
{       
    item.BackColor = Color.White;
    item.ImageIndex = j;

    listView1.Items.Add(item);
}
using(var conn = new MySqlConnection())
{
    var index = 0;
    conn.ConnectionString = connString;
    conn.Open();
    string queryssxxxqbb = "Select * from products where deleted='No'";
    MySqlCommand cmdaaxxxqbb = new MySqlCommand(queryssxxxqbb, conn);
    MySqlDataReader dataReaderxxxxxqbb = cmdaaxxxqbb.ExecuteReader();
    while (dataReaderxxxxxqbb.Read())
    {

        var productname = dataReaderxxxxxqbb["productname"].ToString();
        var productprice = dataReaderxxxxxqbb["productprice"].ToString();
        var picturelink = dataReaderxxxxxqbb["picturelink"].ToString();

        try
        {
            this.imageList1.Images.Add(Image.FromFile(@"\\" + 
                Properties.Settings.Default.Local_Server + 
                "\\Documents\\Stock And Inventory Software\\Product Pictures\\" + 
                picturelink));
        }
        catch
        {
            this.imageList1.Images.Add(Properties.Resources.default_image);
        }

        this.listView1.View = View.LargeIcon;
        this.imageList1.ImageSize = new Size(100, 90);
        this.listView1.LargeImageList = this.imageList1; 

        var item = new ListViewItem();       

        item.Text = productname;
        item.BackColor = Color.White;
        item.ImageIndex = index++;

        listView1.Items.Add(item);
    }
}