how can I dynamically create checkboxes in VB.NET 
Author Message
 how can I dynamically create checkboxes in VB.NET

Hi,
    I have to create dynamically a variable number of checkboxes on a form
depending on the RecordCount of a SQL query.  Let me introduce you the exact
problem:

I have a worker who has a salary. From this salary I must substract some
deductions (taxes, insurances, etc.). The checkboxes are to represent each
deductions and can be checked or unchecked depending if the deduction is
applicable or not to the worker.  Each worker can have different number of
possible deductions depending on their salary and their position in the
company. So a worker could have 3 possible deductions while another could
have 10.(I exagerate, but it's just to let you see the possible difference).
So I must be able to create checkboxes dynamically. And these checkboxes
must handle events. (the same process is used for every checkboxes, so it
can the same method and I'm pretty sure it must be the same method)

I tryed this without success :

Private WithEvents CHKDeductions() as system.windows.forms.checkbox

but the compilator wrote "Cannot declare a WithEvents object as an array" or
something like that. So what is the other way to do it? In VB6, this problem
was easily solvable using control arrays, but it does not seem to be like
this in .NET. And how do i get the Checked property for each of the
checkboxes afterward?

thanks for helping me.



Tue, 12 Apr 2005 12:54:29 GMT  
 how can I dynamically create checkboxes in VB.NET
Are you adverse to using a datagrid?  You can create a
column that is a checkbox and a column that describes what
the checkbox represents.

There may be a way to do what you want, I just don't know
what it is (but would be interested in learning if anyone
wants to post it here).

-Lee

PS. here's a subroutine for adding a checkbox column to a
datagrid:

Private Sub AddDataGridBoolColumnStyle()
  Dim myColumn As DataGridBoolColumn = New
DataGridBoolColumn()

  myColumn.MappingName = "DataColumnName"
  myColumn.HeaderText = "Column Header"
  myColumn.Width = 95
  DataGrid1.TableStyles
("TableStyleName").GridColumnStyles.Add(myColumn)
End Sub

Quote:
>-----Original Message-----
>Hi,
>    I have to create dynamically a variable number of

checkboxes on a form
Quote:
>depending on the RecordCount of a SQL query.  Let me

introduce you the exact
Quote:
>problem:

>I have a worker who has a salary. From this salary I must
substract some
>deductions (taxes, insurances, etc.). The checkboxes are
to represent each
>deductions and can be checked or unchecked depending if
the deduction is
>applicable or not to the worker.  Each worker can have
different number of
>possible deductions depending on their salary and their
position in the
>company. So a worker could have 3 possible deductions
while another could
>have 10.(I exagerate, but it's just to let you see the

possible difference).
Quote:
>So I must be able to create checkboxes dynamically. And
these checkboxes
>must handle events. (the same process is used for every
checkboxes, so it
>can the same method and I'm pretty sure it must be the
same method)

>I tryed this without success :

>Private WithEvents CHKDeductions() as

system.windows.forms.checkbox
Quote:

>but the compilator wrote "Cannot declare a WithEvents

object as an array" or
Quote:
>something like that. So what is the other way to do it?

In VB6, this problem
Quote:
>was easily solvable using control arrays, but it does not
seem to be like
>this in .NET. And how do i get the Checked property for
each of the
>checkboxes afterward?

>thanks for helping me.

>.



Tue, 12 Apr 2005 21:05:30 GMT  
 how can I dynamically create checkboxes in VB.NET
Il cervello cattivo di ThunderMusic produceva il seguente:

Quote:

> Hi,
>     I have to create dynamically a variable number of checkboxes on a form
> depending on the RecordCount of a SQL query.  Let me introduce you the exact
> problem:

> I have a worker who has a salary. From this salary I must substract some
> deductions (taxes, insurances, etc.). The checkboxes are to represent each
> deductions and can be checked or unchecked depending if the deduction is
> applicable or not to the worker.  Each worker can have different number of
> possible deductions depending on their salary and their position in the
> company. So a worker could have 3 possible deductions while another could
> have 10.(I exagerate, but it's just to let you see the possible difference).
> So I must be able to create checkboxes dynamically. And these checkboxes
> must handle events. (the same process is used for every checkboxes, so it
> can the same method and I'm pretty sure it must be the same method)

The easiest solution would be: create checkboxes for all possible cases,
and show only the checkboxes that apply for the actual case - for the
others, set "Visible=False".

--
Tenchi (remove 'spam.be.gone' for emails)

My VB.net Download Manager (Version 1.23.1234.0)
Homepage: http://mitglied.lycos.de/downloadwunder/
Mailing list: http://de.groups.yahoo.com/group/dw-net/



Wed, 13 Apr 2005 06:23:16 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to access the dynamically created checkbox in vb.net

2. deleting dynamically created controls in runtime using vb.net

3. CheckBox.Checked property in the Header of a Dynamically created DataGrid Column

4. dynamically creating checkboxes

5. Dynamically created CheckBox's?

6. How do I create a canned form?

7. VB.NEt Beginner: Creating a COM+ Object in VB.net

8. Event Handling Between Dynamically Loaded User Controls using vb.net

9. Dynamically add ActiveX control to VB.NET Form

10. How to add an activex control dynamically in VB.NET

11. Fill a dropdownlist Dynamically in .Net aspx (VB language)

12. Dynamically Accessing Web Services From VB.NET

 

 
Powered by phpBB® Forum Software