Adding a select column...

P

Paul Mason

Hi folks,

I am aiming to create a "select" column that is unbound on datagrid whose
other columns are all data bound. The idea is to let the user select items
to be printed etc.

The problem I have arises when I want to find out which rows are selected.
The following code is a tester that puts values into a string to be
displayed, but it's representative.

Dim chk As CheckBox

Dim itm As DataGridItem

Dim str As String

For Each itm In Me.dgVialList.Items

chk = CType(itm.Cells(0).Controls(0), CheckBox)

If chk.Checked Then

str += itm.Cells(1).Text & ", "

End If

Next

The problem occurs at chk = CType(itm.Cells(0).Controls(0), CheckBox) where
it says that it cannot cast the item as a checkbox. This collection is base
0?? I have only one template control (ItemTemplate).

Any ideas?

Cheers...P
 
P

Paul Mason

Many apologies folks...I needed to refer to itm.Cells(0).Controls(1). I'm
not sure why this should be so, but I've got it working now.

Cheers...P
 
E

Elton Wang

Hi Paul,

Actually, the better way is:



chk = CType(itm.FindControl(checkbox_ID), CheckBox)



So you don't need to worry about it's in Controls(0) or Controls(1).



HTH
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top