C# 如何设置单击复选框或其文本时选中的winform checkboxlist项?
我正在窗口窗体应用程序中使用复选框列表控件。当用户单击任何一行时,该行变为蓝色,我们通过以下代码获得其选中状态C# 如何设置单击复选框或其文本时选中的winform checkboxlist项?,c#,winforms,checkboxlist,C#,Winforms,Checkboxlist,我正在窗口窗体应用程序中使用复选框列表控件。当用户单击任何一行时,该行变为蓝色,我们通过以下代码获得其选中状态 private void clbRoles_ItemCheck(object sender, ItemCheckEventArgs e) { . . . } 如何仅在单击复选框或其文本时选择复选框 而不是单击复选框文本区域外的行。代码中的某些内容(可能是@markorial建议的事件处理程序)导致了这种行为。请注意,对于下面这样的代码,您只能单击复选框本身(或其标签)来激活它 cla
private void clbRoles_ItemCheck(object sender, ItemCheckEventArgs e)
{
.
.
.
}
如何仅在单击复选框或其文本时选择复选框
而不是单击复选框文本区域外的行。代码中的某些内容(可能是@markorial建议的事件处理程序)导致了这种行为。请注意,对于下面这样的代码,您只能单击复选框本身(或其标签)来激活它
class CheckBoxesWindow: Form {
public Window()
{
this.Build();
var row1 = new ListViewItem( "Do the dishes", 0 );
row1.SubItems.Add( "High" );
row1.Checked = true;
var row2 = new ListViewItem( "Wash sheets", 1 );
row2.SubItems.Add( "Average" );
this.lvView.Items.AddRange( new ListViewItem[]{ row1, row2 } );
}
void Build()
{
var lv = this.BuildListView();
this.Controls.Add( lv );
this.Show();
}
ListView BuildListView()
{
int width = this.ClientSize.Width;
var toret = new ListView{ Dock = DockStyle.Fill };
toret.View = View.Details;
toret.CheckBoxes = true;
toret.Columns.Add( "Desc", (int) ( width * 0.70 ), HorizontalAlignment.Center );
toret.Columns.Add( "Priority", (int) ( width * 0.30 ), HorizontalAlignment.Right );
this.lvView = toret;
return toret;
}
ListView lvView;
}
希望这有帮助。选择与检查不同。这个问题是关于什么的?请详细说明有关问题和预期行为的更多信息。在我看来,如果我理解正确,您有一个row_click事件会更改框的值?