c# - 在 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;
}
}
解决方案
在此示例中,我有 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";
}
推荐阅读
- ios - 1 个视图控制器中的 2 个 tableViews - 错误不断变化
- python-3.x - plotly orca 无法在 aws ec2 实例上运行
- angular - angular 8 代码问题更改日期格式
- python - 从两个 Docker 容器中的 Python 脚本连接到 InfluxDB
- javascript - 在 reactjs 中使用 gmail api 发送带有纯文本、附件和 html 的电子邮件
- r - 将 dplyr 函数映射到 R 数据帧中的每个变量对组合
- scala - 如何在 DataFrame 中的列中找到与其他 DataFrame 中的另一列最接近的值?
- uwp - 用户 OneDrive 上的 UWP 备份
- css - Capybara:匹配具有特定属性但没有任何值的 CSS(例如,匹配,但既不匹配也不匹配)
- ionic-framework - 请在注销 ionic 5 之前使用 login 或 trySilentLogin