Create checkbox in gridview column at runtime

T

Tony WONG

The gridview is created at runtime

there is a column for checkbox (non-databind)

i can create a blank column by the code

Dim tfSelect As New TemplateField
tfSelect.ItemStyle.Width = 80
mygrid.Columns.Add(tfSelect)

but i do not know how to add the checkbox in the column

grateful for any assistance.

thanks.

tony
 
M

Mark Rae [MVP]

The gridview is created at runtime

there is a column for checkbox (non-databind)

i can create a blank column by the code

Dim tfSelect As New TemplateField
tfSelect.ItemStyle.Width = 80
mygrid.Columns.Add(tfSelect)

but i do not know how to add the checkbox in the column

Not quite sure if the syntax is correct as I never go anywhere near VB.NET,
but it's probably something like:

Dim MyCB As New CheckBox
' set any properties on MyCB as necessary
mygrid.Columns(0).Controls.Add(MyCB)

Obviously, you'll need to modify the column number in the third line
above...

Alternatively, you may be able to do this with the tfSelect object directly,
e.g.

Dim tfSelect As New TemplateField
tfSelect.ItemStyle.Width = 80
Dim MyCB As New CheckBox
tfSelect.Controls.Add(MyCB)
mygrid.Columns.Add(tfSelect)
 
T

Tony WONG

Thanks a lot.

i can't do it with just a line of code

finally i make it by refering a Class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top