Cyber_Zeus Posted March 23, 2006 Posted March 23, 2006 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? Quote
Puiu Posted March 24, 2006 Posted March 24, 2006 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 Quote
bri189a Posted March 24, 2006 Posted March 24, 2006 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. Quote
Leaders snarfblam Posted March 24, 2006 Leaders Posted March 24, 2006 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. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.