简体   繁体   English

WPF中ListView和DataGrid的区别?

[英]Difference between ListView and DataGrid in WPF?

I have to retrieve some questions from the database and display them on the user screen dynamically.我必须从数据库中检索一些问题并将它们动态显示在用户屏幕上。 I also need to add some controls in the columns of grid view, basically a question and input box for an answer.我还需要在网格视图的列中添加一些控件,基本上是一个问题和答案的输入框。

Please suggest which one should I use?请建议我应该使用哪一种? ListView or DataGrid ? ListViewDataGrid

Well, in WPF the difference between ListView and DataGrid is just one.好吧,在 WPF 中, ListViewDataGrid之间的区别只是一个。 Editing.编辑。 You need editing use DataGrid , otherwise use ListView .您需要编辑使用DataGrid ,否则使用ListView You can edit in ListView also but it is easier and build in DataGrid .您也可以在ListView中编辑,但它更容易并在DataGrid构建。 Otherwise, whatever can be displayed in DataGrid , can be displayed in ListView .否则,可以在DataGrid显示的任何内容都可以在ListView显示。

One thing which DataGrid supports and ListView doesn't (out of the box) is automatic column generation. DataGrid支持而ListView不支持(开箱即用)的一件事是自动列生成。

You can read this article on CodeProject for a better understanding of DataGrid and also about the major differences between ListView and DataGrid .您可以阅读CodeProject 上的这篇文章,以更好地了解DataGrid以及ListViewDataGrid之间的主要区别。

I'm not a WPF expert, but it terms of just the controls themselves.我不是 WPF 专家,但它只是控件本身的术语。

When thinking of ListView think Windows Explorer, the pane where you see all you're files, thats a ListView.在考虑 ListView 时,请考虑 Windows 资源管理器,您可以在其中看到所有文件的窗格,这就是 ListView。

When thinking data base its usually (I said usually) a data grid, mouse over the gridview tag and read the description.当认为数据库通常(我说通常)是一个数据网格时,将鼠标悬停在gridview标签上并阅读描述。

Some very obvious reasons why you would want a gridview is its directly editable.您需要 gridview 的一些非常明显的原因是它可以直接编辑。 You can have your user enter the questions and the answer in there.您可以让您的用户在其中输入问题和答案。 Note, since ListViewItem is an Content Control you also could customize it easily like this article does .请注意,由于 ListViewItem 是一个内容控件,您也可以像本文一样轻松自定义它。

Also see if this GridView tutorial helps.另请参阅此GridView 教程是否有帮助。

You haven't given much of the description of how you need the UI, but you could play around and do anything you like.您没有详细说明您需要 UI 的方式,但是您可以随意玩弄并做任何您喜欢的事情。

You could even make a User Control for a [Question + Input box for Answer].您甚至可以为 [问题 + 答案输入框] 创建用户控件。 Then you could use a StackPanel (or even a listview) to list them out.然后你可以使用 StackPanel(甚至是一个列表视图)来列出它们。

Hope that helped.希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM