null values

Cyber_Zeus

New member
Joined
Mar 23, 2006
Messages
1
hi guys!
Using a DataReader, I populate a Datagrid with results from an SQL SELECT.
On the grid, I see null values as (null). Id want the grid to write them as an empy string. (i.e. "")

I tried this:
Code:
        Dim table_style As New DataGridTableStyle
        table_style.MappingName = "Rubrica"
        table_style.ReadOnly = True
        Dim column_style As DataGridColumnStyle
        column_style.NullText = ""
        table_style.GridColumnStyles.Add(column_style)
        dgKharta.TableStyles.Add(table_style)
It gives an error at
Code:
        column_style.NullText = ""
<<Object reference not set to an instance of an object>>
I tried with New
Code:
        Dim column_style As New DataGridColumnStyle
But... <<New cannot be used on a class that is declared MustInherit>>

Any suggestions?
 
I could give you a possible solution using sql: you could create a stored proc.
In that stored proc you could create a temporary table where you would store the records obtained with your select query.
After that you do an update on the temp table: update ##Temptbl set column1 = where column1 is null
And you return the temp table: select * from ##Temptbl

PS: Welcome
 
Yes, the errors you got are expected...is there a reason why your just not DataBinding the DataGrid to a DataSet? Your really reinventing the wheel here.
 
[VB]
Dim table_style As New DataGridTableStyle
table_style.MappingName = "Rubrica"
table_style.ReadOnly = True
Dim column_style As DataGridColumnStyle
column_style.NullText = ""
table_style.GridColumnStyles.Add(column_style)
dgKharta.TableStyles.Add(table_style)
[/VB]
If you declare a variable, but never point it to an object you will have a null reference. If it is MustInherit, that means that there is either another class that derives from this class that you can instantiate, or there is a function somewhere that can return such an object.

Looking through the MSDN in the DataGridColumnStyle...
MDSN said:
The System.Windows.Forms.DataGrid control automatically creates a collection of DataGridColumnStyle objects for you when you set the DataSource property to an appropriate data source. The objects created actually are instances of one of the following classes that inherit from DataGridColumnStyle: DataGridBoolColumn or DataGridTextBoxColumn class.

To format the data display, set the Format property of the DataGridTextBoxColumn class to one of the formatting values. For more information about valid formatting values, see Date and Time Format Strings and Standard Numeric Format Strings.
You must either use an existing class that inherits from DataGridColumnStyle, or inherit DataGridColumnStyle and create your own.
 
Back
Top