Datagrid没有更新

时间:2013-08-29 10:17:40

标签: c# wpf datagrid

我的应用程序是用于音乐轨道GUI,目前我有一个数据网格,用户可以将轨道名称导入,轨道名称从csv文件成功导入并正确插入数据库但是我想要DataGrid然后刷新并显示包含新数据的数据,但不执行此操作。我已经为下面的导入按钮添加了我的代码,非常感谢任何帮助

private void btnUploadTrack_Click(object sender, EventArgs e)
    {
         //Browse for file
         OpenFileDialog ofd = new OpenFileDialog();
        //Only show .csv files
        ofd.Filter = "Microsoft Office Excel Comma Separated Values File|*.csv";
        DialogResult result = ofd.ShowDialog();


        //If the user selects a valid file 
        if (result == DialogResult.OK)
        {
            //File is delimited by a comma
            char[] Delimiter = { ',' };

            //New object for string manipulation
            objStringManipulation = new StringManipulation();

            // Parse the csv file
            List<string[]> TrackList = objStringManipulation.parseCSV(ofd.FileName, Delimiter);


            foreach (string[] track in TrackList)
            {
                //Create new object for manipulating the database
                objSqlCommands = new SqlCommands("generic.Tracks", "TrackName");

                char[] de ={ ','};
                StringManipulation sm = new StringManipulation();

                sm.parseCSV(ofd.FileName , de) ;
                List<string[]> newTrack = TrackList.Where(x => x.Length > 12).ToList();
                List<string[]> Results = sm.parseCSV(ofd.FileName, de).Where(x=> x.Length >12).ToList();

                foreach (string[] item2  in Results)
                {
                    foreach (string item in item2)
                    {
                        string y =  Tracklst.ToString();
                        bool answer = y.Contains(item);


                        if(item.Length > 20)
                        {
                                objSqlCommands.sqlCommandInsertorUpdate2("INSERT", item);
                        }

                    }
                  }
              }
           //update the view 
            Tracklst.Update();
            Tracklst.Refresh();


        }
    }

0 个答案:

没有答案
相关问题