Converting from a datagridview check box cell to text box cell

Borix

Newcomer
Joined
May 14, 2008
Messages
9
Hi all,

I am using the DataGridView_CellFormatting() event to format the values of the programmatically added values in a datagridview. Now, while everything else works, my stored procedure returns a column of BIT type. Automatically, it appears, the datagridview transforms that particular column's cells into DataGridViewCheckBoxCell's. However, in the CellFormatting event, I want some text to appear (like "Yes" or "No") instead of a checkbox. When I executed the following code, a casting error appears. So, how can I convert this checkbox column into a textbox column programmatically?

Code:
   [COLOR="Blue"] Private Sub[/COLOR] dgvAnkand_CellFormatting(ByVal sender [COLOR="Blue"]As[/COLOR] Object, ByVal e [COLOR="Blue"]As[/COLOR] System.Windows.Forms.DataGridViewCellFormattingEventArgs) [COLOR="Blue"]Handles [/COLOR]dgvAnkand.CellFormatting

        ' 23 and 24 are the indices of the two BIT columns
        [COLOR="Blue"]If[/COLOR] (e.ColumnIndex = 23 [COLOR="Blue"]OrElse [/COLOR]e.ColumnIndex = 24) _
            [COLOR="Blue"]AndAlso [/COLOR]e.RowIndex <> dgvAnkand.NewRowIndex [COLOR="Blue"]Then[/COLOR]
 
            ' The following returns a casting error: Boolean cannot be converted
            ' to string, etc...
            e.Value = IIf(e.Value, "Yes", "No")
        [COLOR="Blue"]End If[/COLOR]

    [COLOR="Blue"]End Sub[/COLOR]

Thanks in advance.
 
Back
Top