B
Brad Pears
I am using vb .net 2002. I have a datagrid where I am displaying columns
from a table. The columns that are empty are being displayed as "{null}" and
I want them to be just blank. I heard the onl;y way to do this was by using
a table style to map each column and use the .nulltext="" property so that
nulls are displayed as blank...
My question is this...
There are many columns in this particular table that have null values. Is
there a way to set up a table style using a loop to go through eac field in
the table (we are using SQL server) and set the field arccordingly?? I am
currently doing it the long way and I am pretty sure there is a smarter way
to do it...
Below is some sample code for the load event of the form... In this code I
have only dim'd two columns but I have a bunch. There must be an easier way
than what I am doing here. I am think a for next loop must work but what
would the syntax be?
Private Sub frmAssetMaster_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet()
Dim dgTableStyle As DataGridTableStyle
' fill the dataset
SqlDataAdapter1.Fill(ds)
Me.DataGrid1.DataSource = ds
Me.DataGrid1.DataMember = "ComputerMaster"
'Create a data grid table style.
dgTableStyle = New DataGridTableStyle()
'Map the table style to a table
dgTableStyle.MappingName = "ComputerMaster"
' Dim all of the columns you want
Dim dgTextBoxCol As New DataGridTextBoxColumn()
Dim dgTextBoxCol2 As New DataGridTextBoxColumn()
' Set Col 1 properties
dgTextBoxCol.MappingName = "ComputerName"
dgTextBoxCol.NullText = ""
dgTextBoxCol.HeaderText = "Asset Name"
'Set Col 2 properties
dgTextBoxCol2.MappingName = "RAM"
dgTextBoxCol2.NullText = ""
dgTextBoxCol2.HeaderText = "RAM"
' Add the column styles
dgTableStyle.GridColumnStyles.Add(dgTextBoxCol)
dgTableStyle.GridColumnStyles.Add(dgTextBoxCol2)
' Add the table style
Me.DataGrid1.TableStyles.Add(dgTableStyle)
End Sub
from a table. The columns that are empty are being displayed as "{null}" and
I want them to be just blank. I heard the onl;y way to do this was by using
a table style to map each column and use the .nulltext="" property so that
nulls are displayed as blank...
My question is this...
There are many columns in this particular table that have null values. Is
there a way to set up a table style using a loop to go through eac field in
the table (we are using SQL server) and set the field arccordingly?? I am
currently doing it the long way and I am pretty sure there is a smarter way
to do it...
Below is some sample code for the load event of the form... In this code I
have only dim'd two columns but I have a bunch. There must be an easier way
than what I am doing here. I am think a for next loop must work but what
would the syntax be?
Private Sub frmAssetMaster_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet()
Dim dgTableStyle As DataGridTableStyle
' fill the dataset
SqlDataAdapter1.Fill(ds)
Me.DataGrid1.DataSource = ds
Me.DataGrid1.DataMember = "ComputerMaster"
'Create a data grid table style.
dgTableStyle = New DataGridTableStyle()
'Map the table style to a table
dgTableStyle.MappingName = "ComputerMaster"
' Dim all of the columns you want
Dim dgTextBoxCol As New DataGridTextBoxColumn()
Dim dgTextBoxCol2 As New DataGridTextBoxColumn()
' Set Col 1 properties
dgTextBoxCol.MappingName = "ComputerName"
dgTextBoxCol.NullText = ""
dgTextBoxCol.HeaderText = "Asset Name"
'Set Col 2 properties
dgTextBoxCol2.MappingName = "RAM"
dgTextBoxCol2.NullText = ""
dgTextBoxCol2.HeaderText = "RAM"
' Add the column styles
dgTableStyle.GridColumnStyles.Add(dgTextBoxCol)
dgTableStyle.GridColumnStyles.Add(dgTextBoxCol2)
' Add the table style
Me.DataGrid1.TableStyles.Add(dgTableStyle)
End Sub