Re: Format grid column to display "" instead of datetime DBNull (1

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Carlos Lozano wrote:
Hi Chris,

The error is at runtime. It says "object not set to an instance". I know the grid is not the problem as I can see it after it is populated.
I think it refers to the TableStyles object within the Grid. I Added the following line to verify:


int nStyles = oGrid.TableStyles.Count;

nStyles value is zero. I was expecting a value of 1 as the grid was populated from a table.

Just in case you are wondering, the column formatting setGridColumnStyle()
is called after the grid is populated.

Any Ideas?

Thank you,

Carlos Lozano

"Chris" wrote:


Carlos Lozano wrote:

Hello Folks!

I have a grid that populates from a table on SQL Server. All datetime with DBNull value show 1/1/1900 12:00AM ... Instead of just blank ("").

I found a document with the following code, but didn't work.

public void setGridColumnStyle()
{
           DataGridColumnStyle newColStyle;
           newColStyle = oGrid.TableStyles[0].GridColumnStyles[0];
           newColStyle.NullText = "";
}

I tried to customize it to my needs as below:
public void setGridColumnStyle(ref System.Windows.Forms.Grid oGrid, string sTable, string sColumn)
{
DataGridColumnStyle newColStyle;
newColStyle = oGrid.TableStyles[sTable].GridColumnStyles[sColumn];
newColStyle.NullText = "";
}


I always got an error on second line.

I will appreciate any help to do this.

Carlos Lozano
www.caxonline.net


What is the error?  Is the error at runtime or design time...

Chris


If newColStyle = oGrid.TableStyles[0].GridColumnStyles[0]; works and newColStyle returns something and oGrid.TableStyles[sTable].GridColumnStyles[sColumn]; returns nothing then the names you are passing in for either sTable or sColumn is returning nothing. Most likely sTable is the issue.


obj Object = oGrid.TableStyles[sTable];

Run that line of code and see if obj is set to null; if it does it means that name of your tablestyle isn't equal sTable.

oGrid.TableStyles[0].TableName ??? there is some method that will give you the name of your tablesytle, I don't know what it is called off the top of my head.

hope it helps.
Chris
.



Relevant Pages

  • Re: dbGo in Delphi 2006
    ... I just installed Delphi 2006. ... I have a table that populates a grid. ... property of the DBGrid and the DataSet property of the DataSource ...
    (borland.public.delphi.database.ado)
  • Re: dbGo in Delphi 2006
    ... I have a table that populates a grid. ... When a TAdoQuery is opened in the IDE, the grid is populated. ...
    (borland.public.delphi.database.ado)
  • Re: Format grid column to display "" instead of datetime DBNull (1
    ... I think it refers to the TableStyles object within the Grid. ... Carlos Lozano ... >> I have a grid that populates from a table on SQL Server. ... >> sTable, string sColumn) ...
    (microsoft.public.dotnet.languages.csharp)
  • dbGo in Delphi 2006
    ... I have a table that populates a grid. ... When a TAdoQuery is opened in the ... IDE, the grid is populated. ...
    (borland.public.delphi.database.ado)