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
362 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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