Data Grid shows (null)

  • Thread starter Thread starter Doug Bell
  • Start date Start date
D

Doug Bell

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
 
Simple question but hard to do

I think you can set defaut value for that field if it is null
 
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
------------
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top