开发者

WPF Datagrid refresh data

开发者 https://www.devze.com 2022-12-12 12:36 出处:网络
I use the following code to bind an arraylist to a datagrid //fill datagrid public DataTable configData

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] )        
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消