Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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....
Posted
Comments
BillWoodruff 14-Mar-14 9:57am    
Columns of what ? Please give specific details.
Sergey Alexandrovich Kryukov 14-Mar-14 11:30am    
First of all, if you say "CheckBox", the question is: which one? Full type name, please. Do you think there is only one? No.
—SA

1 solution

This code will create CheckBox for each column from list and add it to FlowLayoutPanel:
C#
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:
C#
var checkedColumns = new List<string>();
foreach (CheckBox checkBox in flowLayoutPanel1.Controls)
{
    if (checkBox.Checked)
    {
        checkedColumns.Add(checkBox.Text);
    }
}


Another solution is to use CheckedListBox component.
Add columns to checkedBoxList:
C#
var columns = new List<string>() { "First column", "Second column", "Third column" };
foreach (var column in columns)
{
    checkedListBox1.Items.Add(column);
}


Retrieve checked column names:
C#
var checkedColumns = new List<string>();
foreach (string item in checkedListBox1.CheckedItems)
{
    checkedColumns.Add(item);
}


Hope I helped you.
 
Share this answer
 
v2
Comments
Member 10670136 14-Mar-14 11:51am    
thnx...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900