.net WPF中ListView和DataGrid的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4765080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between ListView and DataGrid in WPF?
提问by MangoTable
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? ListViewor DataGrid?
请建议我应该使用哪一种?ListView或者DataGrid?
回答by Yogesh
Well, in WPF the difference between ListViewand DataGridis just one. Editing. You need editing use DataGrid, otherwise use ListView. You can edit in ListViewalso but it is easier and build in DataGrid. Otherwise, whatever can be displayed in DataGrid, can be displayed in ListView.
好吧,在 WPF 中,ListView和之间的区别DataGrid只是一个。编辑。您需要编辑使用DataGrid,否则使用ListView. 您也可以ListView在DataGrid. 否则,可以在 中显示的任何内容都可以在DataGrid中显示ListView。
One thing which DataGridsupports and ListViewdoesn't (out of the box) is automatic column generation.
DataGrid支持和ListView不支持(开箱即用)的一件事是自动列生成。
You can read this article on CodeProjectfor a better understanding of DataGridand also about the major differences between ListViewand DataGrid.
你可以阅读这篇文章在CodeProject为更好地理解DataGrid并约之间的主要区别ListView和DataGrid。
回答by gideon
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 gridviewtag and read the description.
当认为数据库通常(我说通常)是一个数据网格时,将鼠标悬停在gridview标签上并阅读描述。
Some very obvious reasons why you would want a gridview is its directly editable. 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.
您需要 gridview 的一些非常明显的原因是它可以直接编辑。您可以让您的用户在其中输入问题和答案。请注意,由于 ListViewItem 是一个内容控件,您也可以像本文一样轻松自定义它。
Also see if this GridView tutorialhelps.
另请参阅此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.
希望有所帮助。

