首页 > 解决方案 > 在 ListView 的第一行和第三列添加值

问题描述

我想在多行和多列中添加值,但条件是我希望在特定的行和列中添加值。

// this is my method get called with struct type List 
void showbind(List<binddata> bindinfo)  
{
    foreach (var item in bindinfo)
    {
        string ip = item.serIp;    // structure items
        int col = item.column;
        string sc = item.scipt;
        string o_ut=item.output;

        // here I'm getting the index of row...
        int i = Array.IndexOf(Program.CheckIp.Keys.ToArray(), "ip");  

        // here I want to add the output value at the "col" 
        // number column..... "lstVwServerList" is the item id.
        lstVwServerList.Columns[col].Text = o_ut;
    }
}

标签: c#visual-studiolistviewrow

解决方案


在此示例中,我有 3 列的 listView1,添加 2 行并在每行中更改 2 个值;请为自己定制。

private void button2_Click(object sender, EventArgs e)
{
    string[] row = { "qqq", "ddd", "ccc" };
    var listViewItem = new ListViewItem(row);
    listView1.Items.Add(listViewItem);
    listView1.Items[0].Text = "hi";

    row = new string[3];
    row[0] = "vvv";
    row[1] = "ooo";
    row[2] = "zzz";
    listViewItem = new ListViewItem(row);
    listView1.Items.Add(listViewItem);
    listView1.Items[1].SubItems[1].Text = "hi";
}

推荐阅读