Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > myGridColumn.NullText Help
 

myGridColumn.NullText Help

I have a datasource and with in that i have null fields which i need to turn to "".  

whats wrong with my code.. it keeps saying that im out of the index range.. please help.. 


oConn.Open();
SqlCommand oCMD = new SqlCommand("select * from sometable", oConn);
oCMD.CommandTimeout = 30;

SqlDataAdapter oResults = new SqlDataAdapter();
oResults.SelectCommand = oCMD;

DataSet oDS = new DataSet();
oResults.Fill(oDS, "Accounts");
DataTableCollection oTbls = oDS.Tables;
DataTable tblAccounts = oTbls["Accounts"];
sprContacts.DataSource = tblAccounts;
                                                                //problem area
DataGridColumnStyle myGridColumn;
myGridColumn = sprContacts.TableStyles[0].GridColumnStyles[0];
myGridColumn.NullText = "Null Text";
MigrationUser 1  Friday, July 23, 2004 9:10 AM
ok i jchange the code but now im getting this: Cannot create a child list for field DataGridsprContacts.


oCMD.CommandTimeout = 30;

SqlDataAdapter oResults = new SqlDataAdapter();
oResults.SelectCommand = oCMD;

DataSet oDS = new DataSet();
oResults.Fill(oDS, "Accounts");
DataTableCollection oTbls = oDS.Tables;
DataTable tblAccounts = oTbls["Accounts"];
sprContacts.DataSource = tblAccounts;
sprContacts.DataMember = "DataGridsprContacts";

DataGridColumnStyle tc = new DataGridTextBoxColumn();
DataGridTableStyle ts = new DataGridTableStyle() ;
ts.MappingName = "DataGridsprContacts";
tc.MappingName = "WebSiteURL";
tc.NullText = "HI";
ts.GridColumnStyles.Add(tc);
MigrationUser 1  Friday, July 23, 2004 9:19 AM
TableStyles[0].GridColumnStyles[0];

The numbers between the '[' and ']' are indexes for collections 
[0] is first item in coll and [1] is the 2nd item and so on

so my best gues is that:
   GridcolumnStyles has no entries , item 0 (first) does not exist
   or  tablestyles has no entries , wich  means that gridcolumnstyles has no entries as wel


sprContacts is a Datagrid right, posibly you have 2 add a column and/or a tablestyle

eg:

'Create tableStyle
ExampleTableStyle = new DataGridTableStyle();
ExampleTableStyle.MappingName = "acounts";

'Create ColumnStyle
DataGridColumnStyle myNullCol = new DataGridTextBoxColumn();
   myNullCol.MappingName = "MyNillableField";
   myNullCol.HeaderText = "Posibly Null";
   myNullCol.NullText = "Null Text";

'add the columstyle 2 the tablestyle
   ExampleTableStyle.GridColumnStyles.Add(myNullCol);
'repeat this 4 all the colums 

'Add tableStyle 2  the grid
sprContacts.TableStyles.Add(ExampleTableStyle);





Remco

MigrationUser 1  Friday, July 23, 2004 10:12 AM
sprContacts.DataMember = "DataGridsprContacts";

Datamember Should be a tablename.  when de datasource is a dataset  
eg 
datasource = ods 
datamember = "tblacounts"

Your setting the datasource 2 a table wich is possible but then you should omit the datamember.

ts.MappingName = "DataGridsprContacts";
tc.MappingName = "WebSiteURL";

one mappingname is les confiusing :)


Remco




MigrationUser 1  Friday, July 23, 2004 1:16 PM

You can use google to search for other answers

Custom Search

More Threads

• Custom Column Databinding
• ConnectionStrings in a referenced DLL vs in App
• Help with an error "Concurrency violation: The updateCommand affected 0 of the expected 1"
• Creation of Forms using Wizard and Data Retreival
• Binding Data
• Question about how to sync the tables in a dataset up when the database changes from another source
• XML to DataGridViewCheckBoxCell Problem
• DataGridView Decimal validation on column keypress
• auto height DataGridView rows
• Hummph! Table Data Reverts to Previous...