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";

myGridColumn.NullText Help
maxfiep
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
nharendt
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);
Dewang Ajmera
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