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
358 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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 video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

23 Experts available now in Live!

Get 1:1 Help Now