DataGrid绑定List<String>

直接使用DataGrid.ItemsSource = adp绑定的是一个名为Length的列,显示的是每个项的长度;

需要使用  .Select(x => new { Value = x }).ToList()  才能展示值;

private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            new Thread(() => {
                List<string> adp = MySqlHelper.selectSQL("select name from perinfo;");
                this.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart)delegate {
                    DataGrid.ItemsSource = adp.Select(x => new { Value = x }).ToList();
                });
            }).Start();
        }
posted @ 2019-12-30 17:06  王钰  阅读(728)  评论(0编辑  收藏  举报