我尝试在checkedListBox中显示已检查项目的数量:checkedListBox1.CheckedIndices.Count
但是如果我想在标签上显示它,我该如何更新我的计数?我试图在ItemCheck事件中写下所有内容:
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
label1.Text= checkedListBox1.CheckedIndices.Count;
}
Run Code Online (Sandbox Code Playgroud)
但即使我取消选中项目,计数也会增加:(我很感激任何帮助!
我需要更改CheckedListBox
项目的垂直空间,以便它们适合另一侧的文本框:
CheckedListBox与"TextBox"并排http://i40.tinypic.com/358vt52.png 如何做到这一点?
在做了一些研究后,我发现CheckedListBox
继承ListBox
,所以它必须有它的公共财产ItemHeight
,但由于某种原因它没有
我试过这个:
ListBox l = CheckedList as ListBox;
l.ItemHeight = 30;
Run Code Online (Sandbox Code Playgroud)
但它不起作用
我正在使用c#开发一个Windows窗体应用程序.如何在选中列表框中的项目之间设置空格?
我需要知道 中每个元素的类型是什么CheckedListBox.Items
?是ListViewItem
,Object
还是什么?
我还想知道如何将 a 绑定DataTable
到 aCheckedListBox
并在 Windows 窗体中设置每个项目的 ID 和文本?
我知道如何删除单个checkedItem
的checkedlistbox
.但现在,我想一次性删除所有已检查的项目.
我试过这个:
foreach (var item in List_Frente.CheckedItems)
{
List_Frente.Items.Remove(item);
}
Run Code Online (Sandbox Code Playgroud)
但是你可能知道,它给了我一个错误,说,List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.
我怎么能一键删除所有checkeditems
?
我有下面的代码.我如何设置checkListBox项目前颜色取决于是否选中项目?
private void FindSelectedUserRoles()
{
lblSelectedUser.Text = Code.CommonUtilities.getDgvStringColValue(dataGridViewUserList, "UserName").Trim();
//iterate all roles selected user is member of
for (int i = 0; i < checkedListRoles.Items.Count; i++)
{
string roleName = checkedListRoles.Items[i].ToString();
string selectedUserRoles = Code.MemberShipManager.GetSpecificUsersRoles(lblSelectedUser.Text.Trim());
if (selectedUserRoles.Contains(roleName))
{
checkedListRoles.SetItemChecked(i, true);
//here i want to set item fore colour to green
}
else if (selectedUserRoles.Contains(roleName) == false)
{
checkedListRoles.SetItemChecked(i, false);
//and here, i want item fore colour to remain black
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在将列表中的项目添加到 CheckedListBox。我希望该框向用户显示项目的友好名称,但在用户选择它时有一个“秘密”实际值可供使用。
foreach (string s in x)
{
checkedlistBox1.Items.Add(friendlyValue);
//Now how do I get this to have the real value?
}
Run Code Online (Sandbox Code Playgroud)
使用下拉菜单,我可以将 DisplayName 和 ValueName 设置为某些内容并使用以下内容:
combobox1.Items.Add(new ComboBoxItem { friendlyValue = x, realValue = y });
Run Code Online (Sandbox Code Playgroud)
我似乎无法用 CheckedListBox 做到这一点。
Visual Studio中是否有一个选项可以将CheckedListBox中的所有项目设置为默认选中?我的意思是我希望在启动时检查所有项目,并且用户可以根据需要取消选择项目.
如果没有,我唯一的选择是在构造函数中以编程方式设置所有项目?
我正在研究一个方法然后我意识到我有一个遍历所有checkedItems的foreach循环,而不是遍历所有未检查的项目.
foreach ( object itemChecked in checkedListBox1.CheckedItems)
{(...)}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有办法在不改变代码的情况下做到这一点.问候
我有一个选中列表框,其属性 MultiColumn 设置为 true。我用两行显示控件。
有没有办法自动调整每组列的列宽(以某种方式,每组列的宽度将显示其中的所有文本)?或者只能为所有列设置相同的宽度?