gpt4 book ai didi

C# 添加项目到 ObjectListView

转载 作者:太空宇宙 更新时间:2023-11-03 20:03:39 26 4
gpt4 key购买 nike

我的程序提取 Windows 更新,检测版本号并将它们记录到 ListView 中的列(KB,版本),但我试图将其更改为 ObjectListView所以我可以对列进行排序。我终其一生都无法弄清楚如何将结果写入 ObjectListView,而且我尝试的任何方法似乎都不起作用。这是我当前的代码:

foreach (string file in msu)
{
string KB = GetKBNumber(file);
Expand.MSU(file, TempDirectory + "\\" + KB);
List<string> versions = GetVersionNumbers(TempDirectory + "\\" + KB);

foreach (string version in versions)
{
ListViewItem itm = new ListViewItem(new[] { KB, version });
olvOutput.Items.Add(itm);
}
PerformStep();
}

但它只是将空白数据写入控件。我究竟做错了什么?提前致谢。

编辑:这是 olvOutput 设计器代码:

        // 
// olvOutput
//
this.olvOutput.AllColumns.Add(this.olvKBNumber);
this.olvOutput.AllColumns.Add(this.olvVersion);
this.olvOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.olvOutput.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.olvKBNumber,
this.olvVersion});
this.olvOutput.Location = new System.Drawing.Point(18, 12);
this.olvOutput.Name = "olvOutput";
this.olvOutput.ShowGroups = false;
this.olvOutput.Size = new System.Drawing.Size(571, 193);
this.olvOutput.TabIndex = 8;
this.olvOutput.UseAlternatingBackColors = true;
this.olvOutput.UseCompatibleStateImageBehavior = false;
this.olvOutput.View = System.Windows.Forms.View.Details;
//
// olvKBNumber
//
this.olvKBNumber.AspectName = "";
this.olvKBNumber.CellPadding = null;
this.olvKBNumber.MaximumWidth = 100;
this.olvKBNumber.MinimumWidth = 100;
this.olvKBNumber.Text = "KB Number";
this.olvKBNumber.Width = 100;
//
// olvVersion
//
this.olvVersion.AspectName = "";
this.olvVersion.CellPadding = null;
this.olvVersion.Text = "Version";
this.olvVersion.Width = 113;

最佳答案

将您的第一个代码段修改为:

foreach (string file in msu)
{
string KB = GetKBNumber(file);
Expand.MSU(file, TempDirectory + "\\" + KB);
List<string> versions = GetVersionNumbers(TempDirectory + "\\" + KB);

foreach (string version in versions)
{
olvOutput.AddObject(new { kbAspectName = KB, versionAspectName = version });
}
PerformStep();
}

...并将第二个代码片段修改为:

// 
// olvKBNumber
//
this.olvKBNumber.AspectName = "kbAspectName";

// ...

//
// olvVersion
//
this.olvVersion.AspectName = "versionAspectName";

免责声明:之前从未使用过 ObjectListView,所以我并不是说这是实现您想要的效果的最佳方式。

关于C# 添加项目到 ObjectListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25504782/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com