我浏览了该站点以寻找解决问题的方法,但似乎没有一个能帮助我解决问题。
我遇到的问题是:当我在列表视图中选择一个项目时,它将突出显示。如果我在窗体上的任何位置按它,它将继续突出显示,但是当我在同一窗体上按一个按钮并遍历其代码时,在_Click末尾,ListView项将失去其焦点。在button_Click事件结束时,我也将listview HideSelection设置为false,我也有listview.focus()
。但是,这些方法都无法使焦点集中在列表视图中。在button_Click listview.SelectedItems[0].Focused = true;
的末尾也有这个选项。要注意的一项是列表视图具有组。这会是我遇到的问题吗?如果可以,我该如何解决?在button_click之后获得窗体焦点时,是否可以在窗体上设置此焦点?
编辑:以下是单击按钮。
private void btPowerOn_Click(object sender, EventArgs e)
{
Color colour;
ButtonPower buttonpower = new ButtonPower(this);
var button = sender as Button;
buttonpower.buttonOnOff(button.Name, Convert.ToByte(this.lvVMs_1.SelectedItems[0].Group.Header));
} //<-- Following this the listview has no focus.
另外,名为LvVMs_1的列表视图也在Form1.Design.cs中初始化:
// lvVMs_1
//
this.lvVMs_1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.lvVMs_1.AutoArrange = false;
this.lvVMs_1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lvVMs_1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
this.lvVMs_1.HideSelection = false;
this.lvVMs_1.LabelWrap = false;
this.lvVMs_1.Location = new System.Drawing.Point(8, 25);
this.lvVMs_1.MultiSelect = false;
this.lvVMs_1.Name = "lvVMs_1";
this.lvVMs_1.Size = new System.Drawing.Size(280, 651);
this.lvVMs_1.TabIndex = 52;
this.lvVMs_1.UseCompatibleStateImageBehavior = false;
this.lvVMs_1.View = System.Windows.Forms.View.Tile;
this.lvVMs_1.SelectedIndexChanged += new System.EventHandler(this.lvVMs_1_SelectedIndexChanged);