【发布时间】:2010-02-21 14:42:09
【问题描述】:
我在 C# WinForm 应用程序中使用数据绑定列表框。
当我单击列表框中的某个项目时,表单上的其他任何内容都不起作用,即使我单击关闭按钮,表单也不会关闭。一切正常,直到我选择一个项目。
我尝试做的是在 listbox1_SelectedIndexChanged 中将 listbox1 焦点设置为 false,但这不起作用。
代码示例:这是将列表框分配给数据源的代码:
this.ListBox1.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.table1BindingSource, "PrimaryKeyId", true));
this.ListBox1.DataSource = this.table1BindingSource;
this.ListBox1.DisplayMember = "Name";
this.ListBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.ListBox1.FormattingEnabled = true;
this.ListBox1.ItemHeight = 24;
this.ListBox1.Location = new System.Drawing.Point(185, 28);
this.ListBox1.Name = "ListBox1";
this.ListBox1.Size = new System.Drawing.Size(660, 532);
this.ListBox1.TabIndex = 7;
this.ListBox1.ValueMember = "Name";
this.ListBox1.SelectedIndexChanged += new System.EventHandler(this.ListBox1_SelectedIndexChanged);
ListBox1 未在其他任何地方引用。这是我之前使用的初始代码:
private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox1.Focus().Equals(false);
}
这是我现在运行的代码:
private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
GroupBox1.Focus().Equals(true);
}
然后在 Windows 负载上我有:table1TableAdapter.Fill(this.Application1DataSet.Table1);
我已经调试了 Windows 加载和 listbox1 方法,所以我不认为这是一个循环。此外,应用程序不会崩溃,所以我不认为这是一个循环。
【问题讨论】:
-
我只是把这个放在这里,因为我在谷歌上找不到任何东西。
-
你能发布一个代码示例吗?确保您在单击该项目时没有做其他事情 - 也许您禁用了所有内容,或者您在主线程上陷入了无限循环。
-
除非在其他地方可能存在循环。项目中的代码本来就不多。
-
CW 提出这个问题有什么原因吗?
-
我认为当您自己回答问题时将问题标记为 CW 是一种礼仪。