Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > checkbox control passing null value in datagridview
 

checkbox control passing null value in datagridview

I have a checkbox in a datagridview and it is passing a null value instead of a false/0 when user doesn't click on it. How can I change it, so it passes a value. I already tried passing values explicityly through the bounddatacolumn properties in the datagridview...

ChitownDotNet  Tuesday, September 12, 2006 4:20 PM
Unfortunately none of the solutions suggested worked. Here is what worked for me:
The value passed is not even null. there fore I had to convert to a string and then compare its length..

private void DGView_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
int RowEdited = e.RowIndex;
if (DGView["MfgColumn",
RowEdited].Value.ToString().Length <= 0)
DGView["MfgColumn", RowEdited].Value = 0;
}
ChitownDotNet  Friday, September 15, 2006 7:43 PM
Ken Tucker  Tuesday, September 12, 2006 4:37 PM
It's already set to False..I checked from the designer.
ChitownDotNet  Tuesday, September 12, 2006 6:23 PM
Somebody has gotta know the answer for this :)
ChitownDotNet  Wednesday, September 13, 2006 7:55 PM

How are you getting the values?This works for me



Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim chkCol As New DataGridViewCheckBoxColumn
chkCol.Name = "CheckMe"
chkCol.HeaderText = "Check Me"
DataGridView1.Columns.Add(chkCol)
DataGridView1.AllowUserToAddRows = False
DataGridView1.RowCount = 5
For Each r As DataGridViewRow In DataGridView1.Rows
Dim val As Boolean
val = CBool(r.Cells(0).Value)
Trace.WriteLine(val)
Next
End Sub

End Class




Ken Tucker  Thursday, September 14, 2006 1:56 AM
Have you modified the DataGridViewCheckBoxCell.ThreeState property?
Wang Chi  Thursday, September 14, 2006 1:57 AM
Unfortunately none of the solutions suggested worked. Here is what worked for me:
The value passed is not even null. there fore I had to convert to a string and then compare its length..

private void DGView_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
int RowEdited = e.RowIndex;
if (DGView["MfgColumn",
RowEdited].Value.ToString().Length <= 0)
DGView["MfgColumn", RowEdited].Value = 0;
}
ChitownDotNet  Friday, September 15, 2006 7:43 PM

You can use google to search for other answers

Custom Search

More Threads

• datagridview with datatable contraints enabled
• Get Database definition in C#
• status bar for a form
• DataGridView column valuetype to bitmap.
• Cell value disappears when user clicks a button
• How to change background color of a selected datagrid column?
• Non-null constraint exception with unbound columns
• DataGrid View Grouping ??
• Datagridview problem
• Error Provider creating error but i don't know why