By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,887 Members | 1,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,887 IT Pros & Developers. It's quick & easy.

Data Grid shows (null)

P: n/a
Hi,
I have created a data table that has records with value = Null.

When I use a data grid it shows these values as (null).

can I get it to display them like a zero length string?

Thanks

Doug
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Doug,

You have to use styles for the answer on your question and than this

http://msdn.microsoft.com/library/de...ltexttopic.asp

When you want to know how to make styles you can use the links at the bottom
of this page

I hope this helps?

Cor
Nov 21 '05 #2

P: n/a
Simple question but hard to do

I think you can set defaut value for that field if it is null
Nov 21 '05 #3

P: n/a
Hi,

Add a tablestyle to your grid. Set the nulltext for the
datagridtextboxcolumn to "". Here is a simple example.

Imports System.Data.SqlClient

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim strConn As String

Dim strSQL As String

Dim da As SqlDataAdapter

Dim conn As SqlConnection

Dim ds As New DataSet

strConn = "Server = (local);"

strConn &= "Database = NorthWind;"

strConn &= "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)

da = New SqlDataAdapter("Select * From Customers", conn)

da.Fill(ds, "Customers")

SetupGrid()

DataGrid1.DataSource = ds.Tables("Customers")

End Sub

Private Sub SetupGrid()

Dim ts As New DataGridTableStyle

ts.MappingName = "Customers"

Dim colName As New DataGridTextBoxColumn

With colName

..MappingName = "ContactName"

..HeaderText = "Name"

..Width = 150

End With

Dim colID As New DataGridTextBoxColumn

With colID

..MappingName = "CustomerID"

..HeaderText = "ID"

..Width = 80

End With

Dim colRegion As New DataGridTextBoxColumn

With colRegion

..MappingName = "Region"

..HeaderText = "Region"

..Width = 80

..NullText = ""

End With

ts.GridColumnStyles.Add(colID)

ts.GridColumnStyles.Add(colName)

ts.GridColumnStyles.Add(colRegion)

DataGrid1.TableStyles.Add(ts)

ts = Nothing

colRegion = Nothing

colName = Nothing

colID = Nothing

End Sub

End Class

Ken
------------
"Doug Bell" <dug@bigpond> wrote in message
news:uj**************@TK2MSFTNGP14.phx.gbl...
Hi,
I have created a data table that has records with value = Null.

When I use a data grid it shows these values as (null).

can I get it to display them like a zero length string?

Thanks

Doug

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.