我的程序提取Windows更新,检测版本号并在列表视图中将它们记录到列(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();
}
Run Code Online (Sandbox Code Playgroud)
但它只是将空白数据写入控件.我究竟做错了什么?提前致谢.
编辑:这是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 …Run Code Online (Sandbox Code Playgroud) 我正在尝试将旧项目从BackgroundWorker转换为异步/等待,但我真的很难让进度条更新.我遵循了这篇文章但却无法像以下一样工作:
这是我的代码:
private async void btnStart_Click(object sender, EventArgs e)
{
btnStart.Enabled = false;
pb.Show();
btnCancel.Enabled = true;
var progressIndicator = new Progress<int>(ReportProgress);
List<string> updates = Directory.GetFiles(txtInput.Text).ToList();
try
{
await ProcessUpdates(updates, progressIndicator, _cts.Token);
}
catch (OperationCanceledException ex)
{
MessageBox.Show(ex.Message, "Operation Cancelled");
}
btnStart.Enabled = true;
pb.Hide();
btnCancel.Enabled = false;
}
async Task<int> ProcessUpdates(List<string> updatePaths, IProgress<int> progress, CancellationToken ct)
{
int total = updatePaths.Count;
for (int i = 0; i < updatePaths.Count; i++)
{
ct.ThrowIfCancellationRequested();
string update = updatePaths[i];
ssFile.Text = …Run Code Online (Sandbox Code Playgroud)