【发布时间】:2015-09-09 09:28:35
【问题描述】:
我的程序中有一个选中列表框,允许用户控制在图表上启用的 9 个可能系列中的哪一个。我已经做到了,因此任何时候都只能使用以下代码在图表上启用两个系列:
//if there are two checked items
if (e.NewValue == CheckState.Checked && chListBoxChartSeries.CheckedItems.Count >= 2)
{
//new item cannot be checked
e.NewValue = CheckState.Unchecked;
}
这很好用。然而,我和我的最终用户发现,一个特定系列(checkedlistbox 和图表系列索引 2)实际上没有任何意义,除非它与其他两个系列(索引 3 和 4)进行比较。 我尝试更改上述代码以识别索引 2 处的项目已被选中,并允许我(甚至自动)检查相关索引处的项目。 完整功能如下图:
private void chListBoxChartSeries_ItemCheck(object sender, ItemCheckEventArgs e)
{
int indexA = 2;
//specify indexes for related parameters
int indexB = 3;
int indexC = 4;
//give positive checkstate
CheckState autochecked = CheckState.Checked;
if (chListBoxChartSeries.CheckedItems.Contains(chListBoxChartSeries.Items[indexA]))
{
//do not limit number of checked items
//apply checkstates to items at this index
chListBoxChartSeries.SetItemCheckState(indexB, autochecked);
chListBoxChartSeries.SetItemCheckState(indexC, autochecked);
}
else //does not contain item at index 2
{
//if there are two checked items
if (e.NewValue == CheckState.Checked && chListBoxChartSeries.CheckedItems.Count >= 2)
{
//new item cannot be checked
e.NewValue = CheckState.Unchecked;
}
}
}
这给我带来了各种各样的错误,尽管它们都没有提供特别丰富的信息,而且我在这个论坛上找到的答案似乎与我的问题无关! 我真的不知道我离实现我想要实现的目标还有多远,所以任何建议或正确方向的观点都会有很大帮助!
谢谢, 标记
【问题讨论】:
标签: c# charts checkedlistbox