Home All Groups Group Topic Archive Search About

Implicit conversion from one object to another

Author
23 Jun 2005 11:48 AM
Ben S
Hello,
I am sure there must be a way to do this but I have not found it yet.
I want to be able to loop through all rows in a data grid, check the state
of a checkbox column - and if it is checked for that row then perform some
action.
The code below will do this BUT it implicitly converts a Control to a
CheckBox - which means I can only do this if I switch off Option Strict
(Which I don't want to do).

Any ideas how I could achieve the same with the Option Strick switched on?

Dim ctlChk As CheckBox
For Each Item As DataGridItem In dgMyDataGrid.Items
            ctlChk = Item.Cells(5).Controls(1)
            If ctlChk.Checked Then
                   Do Something...
            End if
Next

--
Ben

Author
23 Jun 2005 12:02 PM
Ben S
I have found a solution - by using DirectCast keyword:

ctlChk = DirectCast(Item.Cells(5).Controls(1), CheckBox)
--
Ben


Show quoteHide quote
"Ben S" wrote:

> Hello,
> I am sure there must be a way to do this but I have not found it yet.
> I want to be able to loop through all rows in a data grid, check the state
> of a checkbox column - and if it is checked for that row then perform some
> action.
> The code below will do this BUT it implicitly converts a Control to a
> CheckBox - which means I can only do this if I switch off Option Strict
> (Which I don't want to do).
>
> Any ideas how I could achieve the same with the Option Strick switched on?
>
> Dim ctlChk As CheckBox
> For Each Item As DataGridItem In dgMyDataGrid.Items
>             ctlChk = Item.Cells(5).Controls(1)
>             If ctlChk.Checked Then
>                    Do Something...
>             End if
> Next
>
> --
> Ben
Author
29 Jun 2005 7:39 PM
Michael Baltic
Add the column to your datasource as a boolean.  Then bind the datasource to
the grid and make the column type a checkbox.  You can then get the value of
the cell as a boolean instead finding the checkbox.

I have never tried this with an asp webgrid, but this is standard practice
with the infragistics webgrid.

This is a standard practice in .net 2.0 gridview.
--
Staff Consultant II - Enterprise Web Services - Cardinal Solutions Group

Future Business Model - National City Mortgage


Show quoteHide quote
"Ben S" wrote:

> Hello,
> I am sure there must be a way to do this but I have not found it yet.
> I want to be able to loop through all rows in a data grid, check the state
> of a checkbox column - and if it is checked for that row then perform some
> action.
> The code below will do this BUT it implicitly converts a Control to a
> CheckBox - which means I can only do this if I switch off Option Strict
> (Which I don't want to do).
>
> Any ideas how I could achieve the same with the Option Strick switched on?
>
> Dim ctlChk As CheckBox
> For Each Item As DataGridItem In dgMyDataGrid.Items
>             ctlChk = Item.Cells(5).Controls(1)
>             If ctlChk.Checked Then
>                    Do Something...
>             End if
> Next
>
> --
> Ben