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
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11881813
Before using Null values , try seting AllowNull property to true.
myGridColumn.AllowNull = True
0
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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