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

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
sbornstein2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
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
sbornstein2Author Commented:
Cant find it with that path you sent.  Can you give me an example?  Thanks
0
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

sbornstein2Author Commented:
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
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
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
sbornstein2Author Commented:
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
sbornstein2Author Commented:
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
sbornstein2Author Commented:
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
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
I think that you cannot replace the null text with only this chunk of code. Sorry ... :(

SoMoS
0
sbornstein2Author Commented:
Thanks SoMoS.  Appreciate your time.  The developer should be controlling the columns that way anyway.  Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.