Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkbox ?

Status
Not open for further replies.

yfbf

Programmer
Oct 2, 2004
24
BE
Hi,

I have many questions about checkbox :


1/I would like to create dynamicaly 8 checkbox into a form.
The name of each checkbox begin with "CHECKBOX_CAM_".

So :

CHECKBOX_CAM_1
CHECKBOX_CAM_2
CHECKBOX_CAM_3
...
CHECKBOX_CAM_8


2/ I would like to set/get some properties like text,position, tag,... with a SQL Database.

3/ I would like to retrieve the state of the group to a byte at any moment. when the user un/select one or more checkbox.


Best Regards


I would like when I select some of checkbox, retrieve the
 
First i would retrieve the stuff you need from the SQL database that you will use to set tag, text, position, etc.
let's say you have created an object with Tag, Position and Text properties and you have retrieved from the DB into an array of these objects.

SomeClass[] sc = GetDBData();
CheckBoxes[] cbs = new CheckBoxes[8];
for (int i=0;i<8;i++)
{
cbs = new Checkbox();
cb.Name = "CHECKBOX_CAM_" + (i+1);
cb.Tag = sc.Tag;
cb.Position = sc.Position;
cb.Text = sc.Text;
}
this.Controls.AddRange(cbs);
The third question is a little more difficult, you could check create a property and in the get accessor check the true false value of each property and pack the values into a byte as follows
public byte SomeProperty
{
get
{
int result = 0;
for (int x=0;x<8;x++)
{
if (cbs[x])
result+= (int)Math.Pow(2,x);
}
return (byte)result;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top