如何为X和Y轴创建动态复选框 [英] how to create dynamic check boxes for X and Y axis
本文介绍了如何为X和Y轴创建动态复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建动态复选框,以便用户可以选择要在X和Y轴上绘制的列。我如何并行创建这些复选框....
i want to create dynamic check boxes so that user can choose columns to be plotted on X and Y axis. how can i create these check boxes in parallel....
推荐答案
此代码将从列表中为每列创建CheckBox并将其添加到FlowLayoutPanel:
This code will create CheckBox for each column from list and add it to FlowLayoutPanel:
var columns = new List<string>() { "First column", "Second column", "Third column" };
foreach (var column in columns)
{
var checkBox = new CheckBox();
checkBox.Text = column;
checkBox.Checked = false;
flowLayoutPanel1.Controls.Add(checkBox);
}
此部分将返回已检查列名称列表:
This part will return list of checked columns names:
var checkedColumns = new List<string>();
foreach (CheckBox checkBox in flowLayoutPanel1.Controls)
{
if (checkBox.Checked)
{
checkedColumns.Add(checkBox.Text);
}
}
另一个解决方案是使用CheckedListBox组件。
添加列的复选框列表:
Another solution is to use CheckedListBox component.
Add columns to checkedBoxList:
var columns = new List<string>() { "First column", "Second column", "Third column" };
foreach (var column in columns)
{
checkedListBox1.Items.Add(column);
}
检索选中的列名:
Retrieve checked column names:
var checkedColumns = new List<string>();
foreach (string item in checkedListBox1.CheckedItems)
{
checkedColumns.Add(item);
}
希望我能帮到你。
Hope I helped you.
这篇关于如何为X和Y轴创建动态复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文