I use the following code to bind an arraylist to a datagrid
//fill datagrid
public DataTable configData
{
get
{
DataSet dsTemp = new DataSet();
DataTable Tables = new DataTable();
dsTemp.Tables.Add(Tables);
dsTemp.Tables[0].Columns.Add("val", System.Type.GetType(
"System.String" ) );
foreach (string str in IMDB.ML.Class.Config.getReadPaths())
{
开发者_如何学C if (str != string.Empty)
{
DataRow myRow = dsTemp.Tables[0].NewRow();
myRow[0] = str;
dsTemp.Tables[0].Rows.Add(myRow);
}
}
return dsTemp.Tables[0];
}
}
However I need to be able to refresh my data after I add some new data to the list.
datagrid.Items.Refresh() doesn't work...
thanks!
first, your returning a DataTable, not an ArrayList. second, if you use a DataView your grid will update when the data updates...
//fill datagrid
public ICollectionView configData
{
get
{
DataTable table = new DataTable();
table.Columns.Add("val", typeof(string) );
foreach (string str in IMDB.ML.Class.Config.getReadPaths())
{
if ( !string.IsNullOrEmpty( str ) )
{
DataRow myRow = table.NewRow();
myRow["val"] = str;
table.Rows.Add(myRow);
}
}
return CollectionViewSource.GetDefaultView( dsTemp.Tables[0] )
}
}
精彩评论