Solved

how can i set default value of checkbox in datagrid = False, the default value is "", it is greyed out and checked

Posted on 2004-08-24
9
359 Views
Last Modified: 2012-05-05
hi, this is how i add a checkbox column to the datagrid, in the datatablestyle

            Dim CheckBox1 As DataGridBoolColumn
            CheckBox1 = New DataGridBoolColumn
            CheckBox1.MappingName = "Checkbox1"
            CheckBox1.ReadOnly = False
            CheckBox1.Width = 1
            tsJob.GridColumnStyles.Add(CheckBox1)

and now the grid is displayed, but all the checkboxes are type of greyed out, but checked, but the value is "" , as opposed to true or false, how can i have the default value in the checkbox = False?
the syncfusion sets the default row by row.
e.g.
tCust.Rows[0]["Current'] = true;
i use a dataview to set the databinding for the datagrid
i can supply a demo piece of code if needed
thanks!
0
Comment
Question by:jxharding
  • 4
  • 3
  • 2
9 Comments
 
LVL 18

Assisted Solution

by:DotNetLover_Baan
DotNetLover_Baan earned 100 total points
ID: 11881451
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11881463
have you tried this

        CheckBox1.NullValue = False
0
 

Author Comment

by:jxharding
ID: 11881620
hi, i tried the checkbox1.nullvalue = false, but i still got the greyed out box, although the statement makes sense.

and i  tried this from the second link:
 myGridColumn.TrueValue = true
 myGridColumn.FalseValue = false
 myGridColumn.NullValue = Convert.DBNull

but still i get the value  = ""

 i even tried:
CheckBox1.NullText = "False"
but nada.
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11881813
Before using Null values , try seting AllowNull property to true.
myGridColumn.AllowNull = True
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11882058
this seems to work

        CheckBox1.NullValue = Convert.DBNull
        CheckBox1.FalseValue = Convert.DBNull
        CheckBox1.TrueValue = True

ofcourse

unchecking will make your boolean value in the database dbnull
0
 

Author Comment

by:jxharding
ID: 11882073
hi, i just tried it, but no go, i typed out a simulation of the problem.
if you could please copy and paste it into a form.
the real dataset is strongly typed, but i kept this one normally typed for copy and pasting .
thanks!


Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim ds As New DataSet
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'DataGrid1
        '
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(32, 32)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(296, 208)
        Me.DataGrid1.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(368, 273)
        Me.Controls.Add(Me.DataGrid1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ds1 As New DataSet("ds")
        Dim dt As New DataTable("Test")
        Dim c1 As New DataColumn("Checked1")
        c1.DataType = System.Type.GetType("System.Boolean")
        dt.Columns.Add(c1)

        ds1.Tables.Add(dt)
        Dim i As Integer

        For i = 0 To 2
            Dim Newrow1 As DataRow
            Newrow1 = dt.NewRow
            ''''''''''Newrow1("Checked1") = False       'this is just a sample, i cannot
            'add this section to the real project
            dt.Rows.Add(Newrow1)
        Next

        Dim dv As New DataView(ds1.Tables("Test"))
        dv = ds1.Tables(0).DefaultView
        DataGrid1.DataSource = dv

        Dim dstyle1 As New DataGridTableStyle
        Dim CheckBox1 As DataGridBoolColumn
        CheckBox1 = New DataGridBoolColumn
        CheckBox1.MappingName = "Checked1"
        CheckBox1.Width = 50

        'ATTEMPTS
        CheckBox1.AllowNull = True
        CheckBox1.TrueValue = True
        CheckBox1.FalseValue = False
        CheckBox1.NullValue = Convert.DBNull

        dstyle1.GridColumnStyles.Add(CheckBox1)
        DataGrid1.TableStyles.Add(dstyle1)
    End Sub
End Class
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 400 total points
ID: 11882138
this seems to work

        CheckBox1.NullValue = Convert.DBNull
        CheckBox1.FalseValue = Convert.DBNull
        CheckBox1.TrueValue = True

ofcourse

unchecking will make your boolean value in the database dbnull

0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11882144
Oeps, pressed submit again
0
 

Author Comment

by:jxharding
ID: 11882274
excellent, thank you both very much!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with checking if excel exist in client's computer 9 43
Encryption Decryption in Oracle 12 105
Tabcontrol Caption? 1 29
Loop through Multiple Processes Async 2 28
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now