使用此代码:
for (int i = 0; i <= (checkedListBoxPlatypi.Items.Count - 1); i++)
{
if (checkedListBoxPlatypi.GetItemCheckState(i) == CheckState.Checked)
{
ReturnListPlatypi.Add(ParsePlatypusID(checkedListBoxPlatypi.GetItemText(i)));
}
}
... 的CheckedListBox通过(FriendlyPlatypus是一个包含内容的字符串)分配给它的文本:
checkedListBoxPlatypi.Items.Add(FriendlyPlatypus);
... ParsePlatypusID()传递“0”...... ???
答案 0 :(得分:2)
我假设您没有在列表框中添加“i”,因此该对象不会有任何文本。您只需要直接使用该对象:
for (int i = 0; i <= (checkedListBoxPlatypi.Items.Count - 1); i++)
{
if (checkedListBoxPlatypi.GetItemCheckState(i) == CheckState.Checked)
{
ReturnListPlatypi.Add(ParsePlatypusID(checkedListBoxPlatypi.Items[i].ToString()));
}
}
事实上,如果你通过数据绑定添加了一个对象,并且想直接进入“DisplayMember”字段,你可以使用:
for (int i = 0; i <= (checkedListBoxPlatypi.Items.Count - 1); i++)
{
if (checkedListBoxPlatypi.GetItemCheckState(i) == CheckState.Checked)
{
ReturnListPlatypi.Add(ParsePlatypusID(checkedListBoxPlatypi.GetItemText( checkedListBoxPlatypi.Items[i])));
}
}