c# - 使用 Mysql 表填充 C# ListView

标签 c# mysql listview

我不明白为什么 ListView 是空的。

enter image description here

enter image description here

刷新按钮 = Button2,这是我的代码:

       private void button2_Click(object sender, EventArgs e)
    {

        MySqlDataAdapter ada = new MySqlDataAdapter("select * from Teams", _dbConnect.getConnection());
        DataTable dt = new DataTable();
        ada.Fill(dt);

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow dr = dt.Rows[i];
            ListViewItem listitem = new ListViewItem(dr["team_id"].ToString());
            listitem.SubItems.Add(dr["team_name"].ToString());
            listView1.Items.Add(listitem);
        }
    }

最佳答案

您应该至少向您的 ListView 添加一列。添加另一列以显示子项。

enter image description here

关于c# - 使用 Mysql 表填充 C# ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30167767/

相关文章:

c# - Windows 8 应用程序中的 toastnotification 不起作用

c# - 更新 MongoDB 集合中的条目

PHP PDO 准备语句——MySQL LIKE 查询

安卓 ListView

c# - 在 C# 中选择具有重复字符的字符串

c# - 是否可以在 C# 控制台中设置制表符大小

mySQL 查询 - #1054 - 未知列 3

php - ZendDb中类似mysql_affected_rows()的函数是什么

java - 更改 ListView 项的颜色

java.lang.NullPointerException : (ListFragment)