[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How can I change Null value in grid column to blank '' instead?

Posted on 2004-11-03
10
Medium Priority
?
530 Views
Last Modified: 2010-04-23
I have a data grid that is populated.  For date fields it show (null) in the cell if the date is null.  I would rather not have to code every query I have to convert as a varchar and then make it ''.  Is there a way to handle this within the grids itself?  Thanks all
0
Comment
Question by:sbornstein2
  • 6
  • 4
10 Comments
 
LVL 5

Expert Comment

by:Ignacio Soler Garcia
ID: 12483952
Yes of course, you must use TableStyles on the Datagrid (it's a property of the Datagrid) and inside this property use the GridColumStyle. There you will find the property NullText for each columm.

DataGrid --> TableStyle --> ColumStyle --> NullText.

I hope this is clear enought.

SoMoS

   
0
 

Author Comment

by:sbornstein2
ID: 12484337
Cant find it with that path you sent.  Can you give me an example?  Thanks
0
 
LVL 5

Accepted Solution

by:
Ignacio Soler Garcia earned 80 total points
ID: 12484432
Yeah, of course:

    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents DataGridTableStyle1 As System.Windows.Forms.DataGridTableStyle
    Friend WithEvents DataGridTextBoxColumn1 As System.Windows.Forms.DataGridTextBoxColumn
    (....)
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        Me.DataGridTableStyle1 = New System.Windows.Forms.DataGridTableStyle
        Me.DataGridTextBoxColumn1 = New System.Windows.Forms.DataGridTextBoxColumn
        (....)
        '
        'DataGrid1
        '
         Me.DataGrid1.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle() {Me.DataGridTableStyle1})
        '
        'DataGridTableStyle1
        '
        Me.DataGridTableStyle1.DataGrid = Me.DataGrid1
        Me.DataGridTableStyle1.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {Me.DataGridTextBoxColumn1})
        '
        'DataGridTextBoxColumn1
        '
----->Me.DataGridTextBoxColumn1.NullText = "xxxx"<-----

Here you have the chain. I hope this is enought now. Remember to set the Mapping attribute of the table style to the name of the table of the DB that it has and to set the Mapping of the DataGridTextBoxColumn1 to the name of the column.

Askme more if you want, it can be a bit confusing ...

SoMoS
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:sbornstein2
ID: 12485182
What if I am not using the column by column and just setting the mapping name to a query and returning it.  Just basic load of grid not using the column layout but just filling it with dataset etc.  Hope this makes sense.  I do it exactly the way your mentioning but another developer was asking me about this.
0
 
LVL 5

Expert Comment

by:Ignacio Soler Garcia
ID: 12485224
I don't understand you. If you don't define one replacement for each column how do you want to do the replacement? Not all the columns can have a blank space (an integer field can't be empty).

SoMoS
0
 

Author Comment

by:sbornstein2
ID: 12485229
What I am trying to say is can you do this for the whole grid instead of laying out the columns one by one?
0
 

Author Comment

by:sbornstein2
ID: 12485243
Such as this without mapping the columns.  This code just loads the query I have to the grid:

        Dim cmd As New SqlCommand
        Dim cn As New SqlConnection
        Dim TestData As New DataSet
        Dim TestAdapter As New SqlDataAdapter
        Dim objDataGridTableStyle As New DataGridTableStyle
        Dim objTextCol As New DataGridTextBoxColumn
        cn = New SqlConnection(gConn)
        cn.Open()
        cmd.Connection = cn

        TestData.Clear()
        DataGrid1.TableStyles.Clear()

        DataGrid1.DataSource = Nothing
        DataGrid1.DataBindings.Clear()
        DataGrid1.Refresh()

        TestAdapter = New SqlDataAdapter("Select * from Provider", cn)

        TestAdapter.Fill(TestData, "Provider")
        DataGrid1.DataSource = TestData.Tables("Provider")
        DataGrid1.DataBindings.Clear()
0
 

Author Comment

by:sbornstein2
ID: 12485261
I understand exactly what your saying in my code I layout the columns with a datagridtextbox and then create the width's etc.  grid style all that.  I have a developer that want to just load up the grid stopping with the code I have above which does fill the grid with all the fields in the select query.
0
 
LVL 5

Expert Comment

by:Ignacio Soler Garcia
ID: 12485283
I think that you cannot replace the null text with only this chunk of code. Sorry ... :(

SoMoS
0
 

Author Comment

by:sbornstein2
ID: 12485465
Thanks SoMoS.  Appreciate your time.  The developer should be controlling the columns that way anyway.  Thanks
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

865 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