当数据来自 SQLITE 数据库时,有没有一种方法可以将列表框中的数据格式化为列

Is there a way that I can format data in a listbox into columns when the data is from an SQLITE database

这是我目前尝试过的方法,但我得到如下所示的错误说明。 ITEMNAME、ITEMQUANTITY 和 ITEMPRICE 是从数据库输入到列表框中的内容。

        AllItems.Items.Clear();
        AllItems.Items.Add(String.Format(listboxformatting, "Item Name", "Item Quantity", "Item Price (£)"));
        sqlite_conn = new SQLiteConnection("Data Source=RetailSystem.db; Version = 3; New = True; Compress = True;");
        try
        {
            SQLiteDataReader sqlite_datareadert;
            sqlite_conn.Open();
            sqlite_cmd = sqlite_conn.CreateCommand();
            sqlite_cmd.CommandText = "SELECT * FROM TblItemStock";
            sqlite_datareadert = sqlite_cmd.ExecuteReader();
            while (sqlite_datareadert.Read())
            {
                string ITEMNAME = sqlite_datareadert.GetString(0);
                int ITEMQUANTITY = sqlite_datareadert.GetInt32(1);
                decimal ITEMPRICE = sqlite_datareadert.GetDecimal(2);

                AllItems.Items.Add(String.Format(listboxformatting,  ITEMNAME + ITEMQUANTITY + ITEMPRICE));
                AllItems.Refresh();
            }
            sqlite_datareadert.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }

ErrorCode

What Get's Displayed

如果您想在表单上放置一个数据网格视图并将其重命名为 _itemsDataGridView 这应该没问题:

    try
    {
        var da = new SQLiteDataAdapter("SELECT * FROM TblItemStock", "Data Source=RetailSystem.db;Version=3;New=True;Compress=True;")

        var dt = new DataTable();
        da.Fill(dt);
        _itemsDataGridView.DataSource = dt;
   
        _itemsDataGridView.Columns[0].HeaderText = "Item Name";
        _itemsDataGridView.Columns[1].HeaderText = "Item Quantity";
        _itemsDataGridView.Columns[2].HeaderText = "Item Price (£)";
        
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }