c# - 在 Visual Studio 中将控件绑定(bind)到 DataGrid 会生成对象引用错误

标签 c# wpf visual-studio-2010 datagrid compiler-errors

我正在使用 Visual Studio 2010。

我正在使用此处描述的程序:MS Instructions for Visual Implementation of bound controls

我在数据源中找到了我想要的数据 View 。我检查我是否需要一个 DataGrid 控件。我将源拖到设计器窗口并将我的网格放入 StackPanel。

一切看起来都很好。除了

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    // Load data into the table dbQueueTable. You can modify this code as needed.
    TradeX_wpf.tradexDataSetTableAdapters.dbQueueTableAdapter tradexDataSetdbQueueTableAdapter = new TradeX_wpf.tradexDataSetTableAdapters.dbQueueTableAdapter();
    tradexDataSetdbQueueTableAdapter.Fill(tradexDataSet.dbQueueTable);
    System.Windows.Data.CollectionViewSource dbQueueTableViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("dbQueueTableViewSource")));
    dbQueueTableViewSource.View.MoveCurrentToFirst();
}

...Fill(tradexDataSet.dbQueueTable) 生成错误提示

An object reference is required for the non-static field, method, or property 'TradeX_wpf.tradexDataSet.dbQueueTable.get'



这是什么意思?我没有完成的文档中缺少什么?我该怎么做才能修复它?

最佳答案

如错误消息所示,您需要创建 tradexDataSet 的实例并将其传递给方法,而不是传递它自己的类名。尝试替换此行:

tradexDataSetdbQueueTableAdapter.Fill(tradexDataSet.dbQueueTable);

有了这个 :
myTradexDataSet = new tradexDataSet();
tradexDataSetdbQueueTableAdapter.Fill(myTradexDataSet.dbQueueTable);

关于c# - 在 Visual Studio 中将控件绑定(bind)到 DataGrid 会生成对象引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21325716/

相关文章:

wpf - DataContext 和 Caliburn

c# - Wpf RichTextBox 换行问题

javascript - RFC 电子邮件正则表达式模式在 Visual Studio 中显示为错误?

c# - 尝试设置配置值 `IHostBuilder` 但未反射(reflect)在启动类中的 ConfigureServices - asp.net core 3.1

c# - 我可以将 html 或 css 类添加到 @Html.DropDownListFor 元素吗

C# 高级标签解析

c# - 使用 Azure Functions 和 .NET 5 将不同的连接字符串传递到 IDesignTimeDbContextFactory(独立)

c# - 隐藏 TreeView 项目

c++ - 如何停止 IntelliSense PCH 警告?

visual-studio - VS2010 中没有 System.Web