CheckedListBox上的DataSource属性对Intellisense是隐藏的.为什么?您可以使用绑定属性使其工作,但我担心它是隐藏的原因,我不应该在CheckedListBox上数据绑定由于一些我不知道的重要原因.
在CheckedListBox上数据绑定好吗?
我想在C#WindowsForms中更改CheckedListBox中chedked项的颜色.
任何人都可以帮我解决这个问题!
如果我在Win表单中有Checked列表框,我填写如下
List<Tasks> tasks = db.GetAllTasks();
foreach (var t in tasks)
tasksCheckedListBox.Items.Add(t.Name);
Run Code Online (Sandbox Code Playgroud)
如何迭代tasksCheckedListBox.Items并将一些复选框设置为已选中?
谢谢
CheckedListBox中的项目是否有标记?或类似的东西?我希望能够存储与我正在显示的项目相关联的ID.
I have a CheckedListBox and I would like to check all the items that are in another List. This code does not work since the CheckedItems property is read-only and the types do not match, but it gives the best idea of what I want to do.
checkedListBox1.DataSource = DataSetSelectAll().Tables[0];
checkedListBox1.ValueMember = "id_table";
checkedListBox1.DisplayMember = "name";
List<tableClass> list = MyCheckedList();
checkedListBox1.CheckedItems = list;
Run Code Online (Sandbox Code Playgroud)
I know this is wrong but do not know how to explain it better.
chkContactType.Items
当我单步执行代码时,我实际上发现它是空的.我甚至添加了一个Watch chkContactType.Items.Count
,它永远不会是0.我现在非常困惑,因为它显然不是因为我的Insert方法工作正常,使用这些相同的框并插入每个项目的Value Member ....
我有一些检查列表框控件,我需要根据项目值设置CheckState,因为这是存储在DB中的现有记录.不幸的是,我只看到了一种通过未存储的索引设置它的方法.索引是控件的本地索引,因此,例如,控件ContactType中有15个项目.指数是0-14.项目价值分别为39,40,41,42,43,44,45,46,47,48,49,50,2077,2078,2079.如何使用Value Member值获取索引值或使用Value Member值设置每个返回项的checkstate?
谢谢
private void PaintDetails(Guid cNoteID)
{
var cNoteDetailDT = CurrentCaseNote.GetCNoteDetail(cNoteID);
LoadCaseNoteDetailData(cNoteDetailDT.Rows[0]);
// Load Contact Type Data for this CaseNote
// contactTypeDT returns ItemID of chk items
// that were checked for this Guid
using (var contactTypeDT = CurrentCaseNote.GetCNoteContactType(cNoteID))
{
if (contactTypeDT.Rows.Count > 0)
foreach (DataRow row in contactTypeDT.Rows)
{
LoadContactTypeData(row);
}
}
}
private void LoadContactTypeData(DataRow row)
{
// This does not work
var theItem = row["ItemID"].ToString();
// itemIndex always ends …
Run Code Online (Sandbox Code Playgroud) 我正在尝试检查已检查列表框中的每个项目,并根据是否选中该项目执行某些操作.我已经能够使用indexCollection获取已检查的项目,但是我无法获取所有项目,我收到此错误'无法将类型为'System.String'的对象强制转换为'System'. Windows.Forms.ListViewItem"
foreach (ListViewItem item in checkedListBox2.Items)
{
if (item.Checked == true)
//do something with item.name
else
//do something else with item.name
}
Run Code Online (Sandbox Code Playgroud)
我不确定为什么它给了我foreach行中的字符串转换错误.我怎么能做到这一点?谢谢.
我不想从硬编码样式的集合中添加项目,我想在按下按钮时从 List<> 填充它们。
首先,我从列表中获取数据,如下所示:
private List<User> _users = new List<User>()
foreach (User user in _users) {
int index = checkedListBoxDepts.Items.Add(user.UserName);
upd.checkedListBoxDepts.Items[index] = user;
}
Run Code Online (Sandbox Code Playgroud)
用于检索已检查的项目:(我将它们放入字符串类型的列表中):
List<string> Names = new List<string>();
foreach (string s in checkedListBoxDepts.CheckedItems) {
Names.Add(s);
}
Run Code Online (Sandbox Code Playgroud) 在C#中,我检查了列表框,我需要将数据存储在数组中,但是当我启动将对象写入数组的事件时,我必须设置数组的大小,我自然设置为数量检查的项目.但是,对于我检查的两个列表框,检查的项目都是1,无论我检查多少.有人可以帮忙吗?
public partial class Form3 : Form
{
public static object[] dtype;
public static bool loaded = false;
bool typeselecte = false;
bool typeselectd = false;
public Form3()
{
InitializeComponent();
}
private void Form3_Shown(object sender, EventArgs e)
{
if (loaded)
{
int counte = 0;
int countd = 0;
types1.Items.AddRange(dtype);
types2.Items.AddRange(dtype);
if (typeselecte)
{
for (int i = 0; i < types1.Items.Count; i++)
{
if (i == Form1.enumber[counte])
{
types1.SelectedItems[i] = Form1.esearch[i];
counte++;
}
}
}
if (typeselectd)
{
for …
Run Code Online (Sandbox Code Playgroud) 我有一个枚举:
enum Presidents
{
Clinton,
Bush,
Obama,
Trump
}
Run Code Online (Sandbox Code Playgroud)
我也有一个CheckedListBox
。我希望它由枚举值组成。我怎样才能做到这一点?
注:一个CheckedListBox
是没有一个CheckBoxList
。请不要参考这个问题。
checkedlistbox ×10
c# ×8
winforms ×6
data-binding ×2
arrays ×1
checklistbox ×1
count ×1
dataset ×1
devexpress ×1
enums ×1
foreach ×1
iteration ×1
vb.net ×1