Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView not displaying text values in a column with mostly numerical values
 

DataGridView not displaying text values in a column with mostly numerical values

Hi,

I have a datagridview with datasource as a dataset table. All columns in the dataset are string type. Dataset is loaded with a delimited file values using OleDB...
My problem is that when the file is loaded into the dataset and displayed in the datagrid, in columns that mostly have numerical values, cells that are meant to contain text are not displayed / are blank. I know and I can see that there should be text displayed but it is not.
If I make a change to a numerical cell in datagridview and enter text into the cell and save datagridview values back to the file, the file will contain the new value, but when reloaded back into the datagridview, the cell is again blank.
It is obvious that the datagridview is expecting a numerical value and when it encounters a text value, it doesnt show it for some reason.
Is there a way to avoid this?

Thanks
MilenaM  Wednesday, September 30, 2009 1:25 PM
Hi,

I think your problem's reason is same with the entry below.

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/d8e38eee-84ac-499c-8157-900978196182

Here is the answer that I posted.

You have a problem with column types.

Here these links describes your problem I think.

http://www.brianpeek.com/blog/archive/2006/04/18/415.aspx
http://neosblogs.blogspot.com/2008/06/how-jet-ole-db-decide-excel-column-type.html

When I increased the value in registry it was a solution for me.
Tamer Oz  Sunday, October 04, 2009 12:23 PM

Hi MilenaM,

You can check the below items to figure what the root cause is:

1.    Check the DataGridViewTextBoxCell to figure out if it has a value.

2.    Check the DataGridViewTextBoxColumn.DefaultCellStyle.ForeColor property to see if the fore color is the same to the back color.

3.    Check if the CellFormatting event of the DataGridView is handler and some code cause the cell to be blank.

 

Could you please provide more information or a code snippet?

 

Regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, October 02, 2009 8:49 AM
Hi Aland,

Thank you for your reply...

I moved away from using dataset as datagridview datasource, I am using the textfieldparser to load delimited text files into the datagridview, and it now works fine.
However with the previous solution which I preferred, after doing more testing, I found that dataset fields with text values in columns that are mainly numeric are not displayed. Datagridview is only displaying whats in the dataset.  Schema file is created based on the delimiter the user specifies...  Here is the code I used:

            conn = New Data.OleDb.OleDbConnection
            conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & IO.Path.GetDirectoryName(filename) & "\;Extended Properties=""TEXT;HDR=" & IIf((withheaders = True), "Yes", "No").ToString & ";FMT=Delimited"""

            conn.Open()
            readAdapter = New OleDb.OleDbDataAdapter("select * from [" & file.ToString & "]", conn)

            data1 = New DataSet

            readAdapter.Fill(frmDataAssistant.data1)

            DataGridView1.DataSource = data1.Tables(0)
            readAdapter.Dispose()
            conn.Close()
            conn.Dispose()

Thanks
MilenaM  Sunday, October 04, 2009 10:56 AM
Hi,

I think your problem's reason is same with the entry below.

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/d8e38eee-84ac-499c-8157-900978196182

Here is the answer that I posted.

You have a problem with column types.

Here these links describes your problem I think.

http://www.brianpeek.com/blog/archive/2006/04/18/415.aspx
http://neosblogs.blogspot.com/2008/06/how-jet-ole-db-decide-excel-column-type.html

When I increased the value in registry it was a solution for me.
Tamer Oz  Sunday, October 04, 2009 12:23 PM

You can use google to search for other answers

Custom Search

More Threads

• Auto general Row ?
• Finding the Values
• SetColumnError changes the Postion of my dataView - why ?
• Bizarre DataBinding Question...
• DatagridViewComboBox: returns wrong selected value when list contains items with the same display text
• how to delete record using datagrid
• Object as DataSource && DataGridView
• DataGridView columns in designer
• I'm using Visual Studio and am trying to search a database
• Setting a numerical value to NULL via editable DataGridView