TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
kainat saleem
NA
7
1.2k
help with dynamic checkboxes
Apr 4 2014 5:17 AM
hi....
i have written following code which displays dynamic check boxes for X and Y co-ordinates...
now, i need help in adding some logic and functionality in them...
i want that the user can check only 1 check box for each co-ordinate i.e 1 for X axis and 1 for Y axis...
also if user select same check boxes for both co-ordinates i.e checkbox 2 for X and also check box 2 for Y error message should be displayed...
i also want to get the index number of checked box as an integer...
as i am new to the language em not getting these things rite...
help is required...
thankyou in advance...
my code is....
------------------------------------------------------------------------------------------------------------------------------------------------------------------
public partial class Form1 : Form
{
CheckBox[] CB2;
CheckBox[] CB;
string[] names = new string[] { "sepal length", "sepal width", "petal length", "petal width" };
int No_Columns;
public Form1()
{
InitializeComponent();
No_Columns=4;
CB=new CheckBox[No_Columns];
for (int i = 0; i < No_Columns; i++)
{
CB[i] = new CheckBox();
CB[i].Left = 20;
CB[i].Top = (i + 1) * 30;
CB[i].Name = "CB" + i.ToString();
CB[i].Text = names[i];//"CB" + i.ToString();
CB[i].CheckedChanged += new EventHandler(CheckedChanged);
// this.Controls.Add(CB[i]);
}
CB2=new CheckBox[No_Columns];
for (int i = 0; i < No_Columns; i++)
{
CB2[i]= new CheckBox();
CB2[i].Left = 190;
CB2[i].Top = (i + 1) * 30;
CB2[i].Name = "CB2" + i.ToString();
CB2[i].Text = names[i];//"CB2" + i.ToString();
CB2[i].CheckedChanged += new EventHandler(CheckedChanged2);
//this.Controls.Add(CB2[i]);
}
for (int i = 0; i < No_Columns; i++) {
this.Controls.Add(CB[i]);
this.Controls.Add(CB2[i]);
}
}
-------------------------- Event HAndlers-------------------------------
private void CheckedChanged(object sender, EventArgs e)
{
CheckBox button = (CheckBox)sender;
//System.Windows.Forms.MessageBox.Show(button.Text.ToString());
for (int i = 0; i < No_Columns; i++)
{
if ("CB" + i.ToString() == button.Text.ToString())
{
}
else
{
CB[i].Checked = false;
}
}
}
private void CheckedChanged2(object sender, EventArgs e)
{
CheckBox button = (CheckBox)sender;
//System.Windows.Forms.MessageBox.Show(button.Text.ToString());
for (int i = 0; i < No_Columns; i++)
{
if ("CB2" + i.ToString() == button.Text.ToString())
{
}
else
{
CB2[i].Checked = false;
}
}
//CheckBox button = (CheckBox)sender;
//button.Checked = true;
}
Reply
Answers (
6
)
insert two table data into database using one .aspx form
Webgrid with Function