Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > dont want to show nulls in grid populated by datatable
 

dont want to show nulls in grid populated by datatable

Dear All,

Im just getting to grips with using datatables with my standard grid control in .net compact 3.5

I have my grid populated by a datatable i filled from a sql database. Some rows have null columns and the grid shows

this as (null) in the column. I would like nothing to be shown at all if its null

Anyone know how to achieve that.

Many thanks

Chris Anderson

chrisanderson  Wednesday, September 17, 2008 8:33 AM

You are going to have to set the datagridtextboxcolumns nulltext

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridcolumnstyle.nulltext.aspx

Ken Tucker  Wednesday, September 17, 2008 11:06 AM

You are going to have to set the datagridtextboxcolumns nulltext

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridcolumnstyle.nulltext.aspx

Ken Tucker  Wednesday, September 17, 2008 11:06 AM

Ken

Many thanks for your reply and sample code

Chris

chrisanderson  Wednesday, September 17, 2008 11:16 AM

Ken

Ive tried the code on the link you sent me:

Dim myGridColumn As DataGridColumnStyle
myGridColumn = dataGrid1.TableStyles(0).GridColumnStyles(0)
myGridColumn.NullText = "Null Text"

When i run this, i get an argumentoutofrange exception - Specified argument was out of the range of valid values.

on the 2nd line??

Any ideas ??

Chris

chrisanderson  Wednesday, September 17, 2008 1:35 PM

Hi

try to use CellFormatting event of DataGridView

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

if (dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString().Equals("null"))

null;

You can use google to search for other answers

Custom Search

More Threads

• Adding a Data Connection that's specific to the Project/Form and making the Data Source path dynamic...
• ContextMenu on NotifyIcon does not respond or freezes
• obtain dataGridViewComboBoxColumn selectedItem
• Typed dataset code change
• Related ComboBox with BindingSource filter
• Grab current record when not using databinding
• How to merge datagridview - datatable
• Databinding: Adding and Reading from Access DB Query
• Duplicate Rows Insereted when DataTable.Rows.Add()
• Extract BindingSource from control.