Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

hi guys!

Using a DataReader, I populate a Datagrid with results from an SQL SELECT.

On the grid, I see null values as (null). I'd want the grid to write them as an empy string. (i.e. "")

 

I tried this:

       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

       column_style.NullText = ""

<<Object reference not set to an instance of an object>>

I tried with New

       Dim column_style As New DataGridColumnStyle

But... <<'New' cannot be used on a class that is declared 'MustInherit'>>

 

Any suggestions?

Posted

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

Posted
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.
  • Leaders
Posted

       Dim table_style As New DataGridTableStyle
       table_style.MappingName = "Rubrica"
       table_style.ReadOnly = True
       [u]Dim column_style As DataGridColumnStyle[/u]
       [u]column_style.NullText = ""[/u]
       table_style.GridColumnStyles.Add(column_style)
       dgKharta.TableStyles.Add(table_style)

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...

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.

[/Quote]

You must either use an existing class that inherits from DataGridColumnStyle, or inherit DataGridColumnStyle and create your own.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...