Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

 

  [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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...