使用datagrid的步骤,将使用objectdataprovider来描述数据库表 [英] Steps to use datagrid that will describe database table using objectdataprovider

查看:247
本文介绍了使用datagrid的步骤,将使用objectdataprovider来描述数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



嗯,我是一名学生,被编写一个连接到数据库的c#项目。我没有在c#之前的程序。现在我有WFP程序可以连接到我的本地MS SQL服务器上的数据库。
现在我有一个任务:
我必须使用datagrid,objectdataprovider显示我的表。我已经在不同的网站上阅读了一些关于它的笔记。我已经尝试了。你能给我写这些一些步骤,帮助我根据我的任务来显示一张桌子。您可以给我一些有用的教程的链接。

解决方案

首先,您必须将要显示的数据存储到某些集合/ list / etc。在您的ViewModel中或有一个返回此集合的方法。



然后您使用 ObjectDataProvider 将此数据公开到您的DataGrid。



将其放入资源并引用如下所示:

 < DataGrid ItemsSource ={StaticResource dataProvKey}/> 

最后一步是定义您的数据将如何显示在您 DataGrid



编辑:

 命名空间ObjectDataProvider 
{
public class MainWindow:Window
{

}
public DataAccess类
{

}
}


sorry for my English.

Well, Im a student that was made to write a c# project that connects to a db. I havent program on c# before. Now I have WFP program that can connects to my db which is situated on my local MS SQL server. Now I've got a task: I must show my tables using datagrid, objectdataprovider. I have already read some notes about it on different sites. I have already tried to do it. Can you write me here some steps that will help me to show a table according to my task. Can you give me some links to helpful tutorials.

解决方案

At first you have to store the data you want to display into some collection/list/etc. in your ViewModel or have a method which returns this collection.

Then you use a ObjectDataProvider to expose this data to your DataGrid.

Place it in the resources and refer to it like so:

 <DataGrid ItemsSource="{StaticResource dataProvKey}"/>

The final step is to define how your data is going to be displayed in you DataGrid.

EDIT:

namespace ObjectDataProvider
{
    public class MainWindow:Window
    {

    }
    public class DataAccess
    {

    }
}

这篇关于使用datagrid的步骤,将使用objectdataprovider来描述数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆