小编And*_*ndy的帖子

以编程方式将列和行添加到WPF Datagrid

我是WPF的新手.我只想知道如何以编程方式将列和行添加到WPF中的DataGrid.我们过去常常在Windows窗体中执行此操作.创建表列和行,并将其绑定到DataGrid.

我相信WPF DataGrid与ASP.net和Windows形式中使用的有点不同(如果我错了,请纠正我).

我有需要在DataGrid中绘制的行数和列数,以便用户可以编辑单元格中的数据.

c# wpf datagrid silverlight-2.0 wpf-controls

68
推荐指数
5
解决办法
23万
查看次数

如何在LINQ函数中定义返回类型?

我想知道如何在以下情况下定义函数中的返回类型.

我有一个产品,我一次返回所有信息或一个产品.

正如您在下面定义的函数中看到的那样.

public static Products GetProducts(int pid) 
{
    var pro = from p in context.Products
              select p;

    if(pid > 0)
        pro =  pro.where(p => p.ProductID ==pid)

    return (Products)p;
}
Run Code Online (Sandbox Code Playgroud)

问题是它给我铸造错误.你可以看到我想要实现的是基于我的参数,它给我一个结果集.一段时间的产品和一些时间单品.我很新的linq所以任何帮助将不胜感激.

错误是无法将类型为'System.Data.Objects.ObjectQuery`1 [TTDCore.Theatres]'的对象强制转换为'TTDCore.Theatres'

当我将它绑定到gridview时.这是一个代码

Products p = Class1.GetProducts(0);

GridView1.DataSource = p;
GridView1.DataBind();
Run Code Online (Sandbox Code Playgroud)

c# linq asp.net entity-framework linq-to-sql

1
推荐指数
1
解决办法
3262
查看次数